1

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.

Saturn
  • 17,888
  • 49
  • 145
  • 271
  • So, you ARE aware that there are other (better) ways to copy one image over another built right in to .Net, correct? – Flipster Jan 06 '11 at 01:27
  • Yes. But I am having my own problems with those other methods. I'm asking this mainly for curiosity purposes while I fix my other problems :) – Saturn Jan 06 '11 at 01:50

1 Answers1

2

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
Chris Haas
  • 53,986
  • 12
  • 141
  • 274