C#图片保真设置

第1步:

using (Graphics g = Graphics.FromImage(img))
                        {
                            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(width, height));
                            g.DrawIcon(icon, iconScreenPoint.X, iconScreenPoint.Y);
                        }

第2步:

 System.Drawing.Imaging.ImageCodecInfo info = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(item => item.FormatDescription.Equals("png", StringComparison.CurrentCultureIgnoreCase));
                System.Drawing.Imaging.EncoderParameters paras = new System.Drawing.Imaging.EncoderParameters();
                paras.Param = new System.Drawing.Imaging.EncoderParameter[]
                {
                    new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality,new long[] {100 })
                };
                if (info != null)
                {
                    img.Save(filePath, info,paras);
                }

你可能感兴趣的:(c#,开发语言)