Bitmap tempBitmap = new Bitmap(w, h);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(tempBitmap);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality =System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, 230, 230);
g.DrawImage(img, rectDestination, 0, 0, 800, 800, GraphicsUnit.Pixel);
tempBitmap.Save(SmallPath);
tempBitmap.Dispose();
img.Dispose();
采用这种方法生成的缩略图片的大小(不是说图片尺寸)太大,有时比原图片还要大,请问有没有什么方法解决
------解决方案--------------------------------------------------------
tempBitmap.Save(SmallPath);
看看你保存成什么格式文件了!
另外在代码中设置一些参数,例如所支持的颜色数量、你写的HighQuality等等,这些都是增大尺寸的原因。
------解决方案--------------------------------------------------------
/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="sourcePicture">源图(绝对路径)</param>
/// <param name="targetPicture">缩略图(绝对路径)</param>
/// <param name="thunbmailWidth">缩略图宽度</param>
/// <param name="thunbmailHeight">缩略图高度</param>
/// <param name="makeModel">生成缩略图的方式(可用值为1:指定高宽缩放,可能变形;2:指定宽,高按比例;3:指定高,宽按比例;4:指定高宽裁减,不变形;)</param>
public static void MakeThumbnail(string sourcePicture, string targetPicture, int thunbmailWidth, int thunbmailHeight, int makeModel)
{
System.Drawing.Image m_imgSource = System.Drawing.Image.FromFile(sourcePicture);
int m_iTargetWidth = thunbmailWidth;
int m_iTargetHeight = thunbmailHeight;
int x = 0;
int y = 0;
int m_iSourceWidth = m_imgSource.Width;
int m_iSourceHeight = m_imgSource.Height;
switch (makeModel)