.NET ez 2012-06-20
C#可以使用Drawing處理圖片,但儲存時預設壓縮品質較差,使用下面方法可以自訂壓縮比率。
System.Drawing.Image image = System.Drawing.Image.FromFile(@"C:\a.png"); EncoderParameters myEncoderParameters = new EncoderParameters(1); myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, Convert.ToInt64(60)); //品質60 image.Save(@"C:\b.png", GetEncoder(ImageFormat.Png), myEncoderParameters); //儲存成png image.Dispose(); private ImageCodecInfo GetEncoder(ImageFormat format) { ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders(); foreach (ImageCodecInfo codec in codecs) { if (codec.FormatID == format.Guid) return codec; } return null; }
標籤: .NET