Combining two .png images into one image using .NET
- by Omega
I have two (actually many) .png images in my application. Both have transparent areas here and there.
I want, in my application, to take both images, combine them, and display the result in a picture box. Later I want to save the result through a button.
So far I managed to find the two images and combine them, but it seems the transparency thing won't work. I mean, if you put one image over another, only the top image is visible as the result because, apparently, the image's background is a plain white box. Which is not.
Here is a bit of my code:
Dim Result As New Bitmap(96, 128)
Dim g As Graphics = Graphics.FromImage(Result)
Dim Name As String
For Each Name In BasesCheckList.CheckedItems
Dim Layer As New Bitmap(resourcesPath & "Bases\" & Name)
For x = 0 To Layer.Width - 1
For y = 0 To Layer.Height - 1
Result.SetPixel(x, y, Layer.GetPixel(x, y))
Next
Next
Layer = Nothing
Next
resourcesPath is the path to my resources folder. Bases is a folder in it. And Name is the image's name.
Thank you.