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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With