使用 Alpha 通道调整图像大小
我正在编写一些代码来生成图像 - 本质上我有一个很大并且包含透明区域的源图像。
我使用 GDI+ 打开该图像并添加其他对象。
接下来我想做的是将这个新图像保存得更小,因此我使用了 Bitmap 构造函数,它接受源 Image 对象以及高度和宽度,然后保存它。
我原本期望 Alpha 通道像颜色通道一样平滑,但这并没有发生——它确实产生了几个半透明像素,但总体来说它是非常块状的。 是什么赋予了?
Using img As New Bitmap("source100x100.png")
''// Drawing stuff
Using simg As New Bitmap(img, 20, 20)
simg.Save("target20x20.png")
End Using
End Using
编辑:我认为我想要的是超级采样,就像 Paint.NET 设置为“最佳质量”时所做的那样
I am writing some code to generate images - essentially I have a source image that is large and includes transparent regions.
I use GDI+ to open that image and add additional objects.
What I want to do next is to save this new image much smaller, so I used the Bitmap constructor that takes a source Image object and a height and width, then saved that.
I was expecting the alpha channel to be smoothed like the color channels, but this did not happen -- it did result in a couple of semitransparent pixels, but overall it is very blocky. What gives?
Using img As New Bitmap("source100x100.png")
''// Drawing stuff
Using simg As New Bitmap(img, 20, 20)
simg.Save("target20x20.png")
End Using
End Using
Edit: I think what I want is SuperSampling, like what Paint.NET does when set to "Best Quality"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在新位图上绘制图像,而不是从图像创建新位图。
只需指定大小即可创建一个空位图,然后使用 Graphics.FromImage 方法为该位图创建一个 Graphics 对象。 使用
DrawImage
方法将图像绘制到新位图上。Graphics
对象中的诸如Interpolationmode
和PixelOffsetMode
之类的属性可用于控制图像的缩放和绘制方式。Draw the image on the new bitmap instead of creating the new bitmap from the image.
Create an empty bitmap by just specifying the size, then use the
Graphics.FromImage
method to create aGraphics
object for the bitmap. Use theDrawImage
method to draw the image onto the new bitmap.There are properties like
Interpolationmode
andPixelOffsetMode
in theGraphics
object that you can use to control how the image is scaled and drawn.