使用图形类设置插值后如何保存位图
此代码调整图像大小并将其保存到磁盘。
using (var medBitmap = new Bitmap(fullSizeImage, newImageW, newImageH))
{
medBitmap.Save(HttpContext.Current.Server.MapPath("~/Media/Items/Images/" + itemId + ".jpg"),
ImageFormat.Jpeg);
}
但如果我想使用图形类来设置插值,我该如何保存呢?图形类有一个 save 方法,但它不带任何参数。如何像位图一样将其保存到磁盘?这是修改后的代码片段:
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);
}
我只需要设置插值,然后将其保存到磁盘。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Graphics 对象上调用 DrawImage 来更新位图:
Call DrawImage on the Graphics object to update the bitmap:
创建一个具有所需大小的新位图并设置插值模式。然后使用 Graphics.DrawImage 将完整尺寸的图像绘制到新的位图中。
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.