Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top