Transparency in Bitmaps
Posted by Jeffrey Vanneste at 09:53 PM on February 25, 2004
Category:
Development
I've started working on my new game although I'm not quite sure what it will be in the end. I'm pretty sure it will be a puzzle game on a board made of hexagons (I have a couple hexagon-ish games in mind) so I've just been working on drawing hexagons so far. I originally tried just using DrawPolygon to draw the polygons but they looked so boring so I figured I'll make up some nice looking hexagon bitmap and just draw that. Well, I haven't ever had to draw a bitmap with transparency so I looked into that tonight. Apparently the MakeTransparent method isn't available in the Compact Framework so I had to see if there was another way to do it. My last resort was to loop through all the pixels of the bitmap and turn the colors that I wanted to be transparent manually but thankfully I don't have to do that. Anyways, using the ImageAttributes class it was quite easy to specify which color to be transparent. So here it is: Graphics g = e.Graphics; // draw hexagon with transparent background // draw hexagon without transparent background This draws the following bitmaps on the screen:
That's pretty much it. My sample project can be dowloaded here. Later I'll post some code on drawing the hexagon so they are connected properly. I found the secrect is multiples of 4. Till then, enjoy. |
