FileStream fs = new FileStream(@"C:\aaa.JPG", FileMode.Open);
Bitmap img1 = new Bitmap(fs);
Bitmap img2 = new Bitmap(1024, 768, PixelFormat.Format24bppRgb);
img2.SetResolution(900.0F, 900.0F);
using(Graphics g = Graphics.FromImage(img2))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(img1, new Rectangle(0, 0, img2.Width, img2.Height), 0, 0, img1.Width, img1.Height, GraphicsUnit.Pixel);
g.Dispose();
img2.Save(@"d:\yyyyy.bmp", ImageFormat.Bmp);
}
public static Bitmap KiResizeImage(Bitmap bmp, int newW, int newH)
{
try
{
Bitmap b = new Bitmap(newW, newH);
Graphics g = Graphics.FromImage(b);
// 插值算法的质量
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
g.Dispose();
return b;
}
catch
{
return null;
}
}