我有以下代碼來拍攝圖像並生成縮略圖。C#生成縮略圖文件大小
如何改變質量或壓縮以編程方式獲得較小的文件大小?
Image thumbNail = image.GetThumbnailImage(Width, Height, null, new IntPtr());
我有以下代碼來拍攝圖像並生成縮略圖。C#生成縮略圖文件大小
如何改變質量或壓縮以編程方式獲得較小的文件大小?
Image thumbNail = image.GetThumbnailImage(Width, Height, null, new IntPtr());
如果你真的需要在製作縮略圖更好的控制,你會好起來的生產自己手動生成更小尺寸和不同質量的圖像。 GetThumbnailImage不會給你太多的控制。
看到這篇文章是如何完成的。 http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing
在保存thumbNail
與Image.Save
你可以通過一個EncoderParameter
指定的質量。請參閱:Reducing JPEG Picture Quality using C#
EncoderParameter epQuality = new EncoderParameter(
System.Drawing.Imaging.Encoder.Quality,
(int)numQual.Value);
...
newImage.Save(..., iciJpegCodec, epParameters);
您不使用GetThumbnailImage API:
protected Stream ResizeImage(string source, int width, int height) {
using (System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(source))
using (System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height))
using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(newBmp))
{
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphic.DrawImage(bmp, 0, 0, width, height);
MemoryStream ms = new MemoryStream();
newBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms;
}
}
-1再次問同樣的問題:http://stackoverflow.com/questions/684092/create-thumbnail-and-reduce-image-size –
究竟你是否經常要問同樣的問題? :http://stackoverflow.com/questions/672807/generating-jpg-thumbnails-in-dotnet –