原本寬度為300 的圖片ImagePhoto 大小為 30KB
FixedSize(ImagePhoto,300) 之后 圖片 變?yōu)?20KB 了,圖片質(zhì)量下降了很多
怎么弄讓圖片質(zhì)量和原來的一樣呢?
public static Image FixedSize(Image imgPhoto, int Width) { int sourceWidth = imgPhoto.Width; int sourceHeight = imgPhoto.Height; int w, h; if (sourceWidth > Width) { decimal nPercent = (decimal)sourceWidth / Width; w = Width; h = (int)Math.Round((decimal)sourceHeight / nPercent, 0); } else { w = sourceWidth; h = sourceHeight; } Bitmap bmPhoto = new Bitmap(w, h, imgPhoto.PixelFormat); bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); Graphics grPhoto = Graphics.FromImage(bmPhoto); grPhoto.CompositingQuality = CompositingQuality.HighQuality; grPhoto.SmoothingMode = SmoothingMode.HighQuality; grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, w, h), new Rectangle(0, 0, sourceWidth, sourceHeight), GraphicsUnit.Pixel); grPhoto.Dispose(); return bmPhoto; }
使用Graphics 保存 圖片質(zhì)量很差,怎么回事?
喵喵時(shí)光機(jī)
2018-12-07 04:11:23