There is no such a thing as "transparent" pixels. All you can do is tag them for the renderer so that it will know they aren't supposed to be displayed. here are the 3 most common ways of tagging but which one you use depends on when you're doing for rendering:
- Use a transparency map: a second pixmap which indicates the "level" of transparency of each pixel. The rendered then uses that as a weighting value to combine the top and bottom layers in the final color. If you just want binary transparency (opaque/transparent), you can use a bitmap and use a simple XOR on each pixel which makes it very fast.
- Define a "transparent color". You can then XOR it with the transparent color and the bottom layer. Also very fast and doesn't require any additional storage. It does have some side effects, though (one color cannot be used in the top layer image, for instance)
- use the last byte of the 32-bits bitmap as the transparency level (alpha channel). In effect, you store the transparency map (255 distinct levels of transparency) with the image.
Now, in your case, since you seem to be only copying a rectangle over a rectangle, another aproach that would be: create a canvas of the same size as the final image, copy the inferior rectangle on it and the draw the to layer on top of it.