使用 Alpha 通道调整图像大小

发布于 2024-07-14 09:45:00 字数 474 浏览 4 评论 0原文

我正在编写一些代码来生成图像 - 本质上我有一个很大并且包含透明区域的源图像。

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女 2024-07-21 09:45:01

在新位图上绘制图像,而不是从图像创建新位图。

只需指定大小即可创建一个空位图,然后使用 Graphics.FromImage 方法为该位图创建一个 Graphics 对象。 使用 DrawImage 方法将图像绘制到新位图上。

Graphics 对象中的诸如 InterpolationmodePixelOffsetMode 之类的属性可用于控制图像的缩放和绘制方式。

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 a Graphics object for the bitmap. Use the DrawImage method to draw the image onto the new bitmap.

There are properties like Interpolationmode and PixelOffsetMode in the Graphics object that you can use to control how the image is scaled and drawn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文