もっと詳しく
Rendering images with transparency is not supported by the CompactFramework running on WindowsCE. The transparent areas of the image are rendered in black color. This effect is disturbing, especially when you want to draw icons that do not have a rectangular shape.
A workaround exists through setting a transparency key color that will be ignored by the rendering engine. Use the class ImageAttributes and specify the transparency key color with a threshold value. All colors between the key and the threshold won’t be rendererd then. Of course you will have to change your image files by painting the background in one of the specified colors in the transparency range.
Bitmap image = new Bitmap(filname);
ImageAttributes transparency = new ImageAttributes();
transparency.SetColorKey(Color.Red, Color.Red);
When drawing the image using a Graphics object, you have to submit the transparency values:
graphics.DrawImage(image, rect, 0, 0, 32, 32, GraphicsUnit.Pixel, transparency);
This solution is very simple but has some limitations. Since JPEG and PNG use compression and colors are slightly smudged, the transparency comes out best, if you use uncompressed bitmap files, since each pixel has exactly the value you want it to have (transparency key or real color).
I use this technique in a mobile navigation application that renders icons on the map which shall appear with transparent background. It also works better when you keep the problem in mind during the design of the icons you want to draw.