简体   繁体   English

如何在使用图形 class 设置插值后保存 bitmap

[英]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?但是如果我想用图形class来设置插值,怎么保存呢? The graphics class has a save method, but it doesn't take any parameters.图形 class 有保存方法,但不带任何参数。 How do I save it to disk like the bitmap?如何将它保存到磁盘,如 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:在图形 object 上调用 DrawImage 以更新 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.使用您想要的大小创建一个新的 Bitmap 并设置插值模式。 Then use Graphics.DrawImage to draw the full sized image into the new bitmap.然后使用 Graphics.DrawImage 将全尺寸图像绘制到新的 bitmap 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM