开发者

VB .NET picture GetPixel & SetPixel: Include alpha?

开发者 https://www.devze.com 2023-02-02 11:07 出处:网络
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)

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 th开发者_如何学运维e same size. Both have transparent areas.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消