public static void MakeThumbnail(string originalImagePath, int width, int height)
{
string type = Path.GetExtension(originalImagePath).ToUpper();
MemoryStream strea = new MemoryStream();
string path = Path.GetTempPath() + Path.GetFileNameWithoutExtension(originalImagePath) + ".tmp";
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);
int towidth = width;
int toheight = height;
int ow = originalImage.Width;
int oh = originalImage.Height;
if ((double)originalImage.Width / (double)towidth < (double)originalImage.Height / (double)toheight)
{
toheight = height;
towidth = originalImage.Width * height / originalImage.Height;
}
else
{
towidth = width;
toheight = originalImage.Height * width / originalImage.Width;
}
//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(System.Drawing.Color.Transparent);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载