生成小图
来源:互联网 发布:apache tomcat 7.0.75 编辑:程序博客网 时间:2024/05/16 10:11
public void GetSmallImage(string ImagePath, int width)
...{
File.Copy(ImagePath, ImagePath + ".jpg");
Bitmap bitmap = new Bitmap(width, Convert.ToInt32((double)(width * 0.75)));
System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath + ".jpg");
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
graphics.Dispose();
bitmap.Save(ImagePath);
bitmap.Dispose();
image.Dispose();
File.Delete(ImagePath + ".jpg");
}
...{
File.Copy(ImagePath, ImagePath + ".jpg");
Bitmap bitmap = new Bitmap(width, Convert.ToInt32((double)(width * 0.75)));
System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath + ".jpg");
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
graphics.Dispose();
bitmap.Save(ImagePath);
bitmap.Dispose();
image.Dispose();
File.Delete(ImagePath + ".jpg");
}