1.
bComb is new variable which will have same size of bmp3 ....... am i right ?
yes , It's a bitmap with size of bmp3
which we'll use to draw some other stuff on it but now It contains only empty pixels , nothing more !
2.
using (Graphics g = Graphics.FromImage(bComb))
this line gives us the ability to draw whatever we need on bComb
it can be a bitmap or a rectangle or simply anything !
3.
g.DrawImage(this.pictureBox1.Image, 0, 0, bComb.Width, bComb.Height);
here it draws the this.pictureBox1.Image
to the bitmap (bComb
) from point (0,0)
to (bComb.Width,bComb.Height)
which will contain the whole bitmap indeed
4.
g.DrawImage(bmp3, 0, 0, bComb.Width, bComb.Height);
bmp3
is being drawn to bComb
here again from point (0,0)
to (bComb.Width,bComb.Height)
the bitmaps are being drawn on each other from the same point and with the same size , the point is if they contain transparent pixels the result will be a combination of those bitmaps , otherwise you will just see the bmp3
which was drawn later and no clue of the first image , and we use (0,0) because it's the beginning point of our bitmap , we could use any other point to draw our stuff but in this way we leave some pixels behind so why would we ? :)
- Update : It's totally possible to draw images over each other and you're right if they have transparent pixels the result will be like marge , but as you mentioned if the last bitmap does not contain any transparent pixels so the only picture we're gonna see is the last one and we won't be able to see the previous bitmaps because those pixels are over-written by the last bitmap feel free to to use some png semi-transparent images and drawing them on top of each other and see the result , and I'm afraid , I don't know any built-in gdi+ function for image comparison but you can do it easily by
GetPixel()
function in gdi+ and comparing each pixel from one bitmap to another or you may use unsafe code and access memory directly it totally depends on you but If you want a clean and easy way go withGetPixel()
! you may also take a look at Intel's open-cv library for image processing , hope it helps