How to save a bitmap after setting interpolation with graphics class
This code resizes an image and saves it to disk.
using (var medBitmap = new Bitmap(fullSizeImage, newImageW, newImageH))
{
medBitmap.Save(HttpContext.Current.Server.MapPath("~/Media/Items/Images/" + itemId + ".jpg"),
ImageFormat.Jpeg);
}
But if I want to use the graphics class to set the interpolation, how do I save it? The graphics class has a save method, but it doesn't take any parameters. How do I save it to disk like the bitmap? Heres a modified code snippet:
using (var medBitmap = new Bitmap(fullSizeImage, newImageW, newImageH))
{
var g = Graphics.FromImage(medBitmap);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//What do开发者_开发百科 I do now?
medBitmap.Save(HttpContext.Current.Server.MapPath("~/Media/Items/Images/" + itemId + ".jpg"),
ImageFormat.Jpeg);
}
I just need to set the interpolation and then save it to disk.
Call DrawImage on the Graphics object to update the bitmap:
using (var medBitmap = new Bitmap(fullSizeImage, newImageW, newImageH))
{
using (var g = Graphics.FromImage(medBitmap))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(medBitmap, 0, 0);
}
medBitmap.Save(HttpContext.Current.Server.MapPath("~/Media/Items/Images/" + itemId + ".jpg"), ImageFormat.Jpeg);
}
Create a new Bitmap with the size you want and set the interpolationMode. Then use Graphics.DrawImage to draw the full sized image into the new bitmap.
精彩评论