VB .NET 图片 GetPixel & SetPixel:包括阿尔法?

发布于 2024-10-10 10:00:19 字数 280 浏览 0 评论 0原文

我正在尝试使用 GetPixel 和 SetPixel 将一张图片的内容复制到另一张图片(我知道还有其他方法可以这样做,但我想尝试这个是有原因的;D)

无论如何,这些图片是 .png 图像,所以它们包括透明度设置。

但由于某种原因,当我使用 GetPixel & SetPixel 将一张图像放在另一张图像上,看起来第二张图像完全取代了另一张图像。我的意思是,当我使用 GetPixel 和 GetPixel 时,似乎不遵守透明度设置。设置像素。

两个图像具有相同的尺寸。两者都有透明区域。

I am trying to use GetPixel and SetPixel to copy the contents of one picture to another (I know there are other methods to do so, but there are reasons I want to try this ;D)

Anyway, the pictures are .png images, so they include transparency settings.

But for some reason, it seems like when I use GetPixel & SetPixel to put one image over another, it seems the second image completely replaces the other one. I mean, it seems the transparency settings are not respected when I use GetPixel & SetPixel.

Both images have the same size. Both have transparent areas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

强辩 2024-10-17 10:00:19

在调用 SetPixel() 之前,您需要调用 MakeTransparnet()。下面是一些代码,它将 alpha 图像中第一个像素的内容复制到另一个图像上,并保留第一个图像的 alpha 通道:

    Using img1 = New Bitmap("c:\Users\Owner\Desktop\1.png")
        PX = img1.GetPixel(0, 0)
    End Using

    Using img2 = New Bitmap("c:\Users\Owner\Desktop\2.png")
        img2.MakeTransparent() '//Sets the transparent value and converts the image to Format32bppArgb
        img2.SetPixel(0, 0, PX)
        img2.Save("c:\Users\Owner\Desktop\3.png")
    End Using

Before calling SetPixel() you need to call MakeTransparnet(). Here's some code that copies the contents of the first pixel in an alpha-image onto another image and retain's the first image's alpha channel:

    Using img1 = New Bitmap("c:\Users\Owner\Desktop\1.png")
        PX = img1.GetPixel(0, 0)
    End Using

    Using img2 = New Bitmap("c:\Users\Owner\Desktop\2.png")
        img2.MakeTransparent() '//Sets the transparent value and converts the image to Format32bppArgb
        img2.SetPixel(0, 0, PX)
        img2.Save("c:\Users\Owner\Desktop\3.png")
    End Using
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文