Bitmap bm= (Bitmap)Bitmap.FromFile(FileName);
int shtWidth, shtHeight;
if (bm.Width>bm.Height)
{
shtWidth = 250;//max width
shtHeight=bm.Height*shtWidth/bm.Width;
}
else
{
shtHeight = 250;//max height
shtWidth = bm.Width*shtHeight/bm.Height;
}
Bitmap resized = new Bitmap(shtWidth, shtHeight);
Graphics g = Graphics.FromImage(resized);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bm, new Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel);
g.Dispose();
bm.Dispose();
resized.Save(SCANPREVIEWFILE, ImageFormat.Jpeg);
沒有留言:
張貼留言