The iPhone's popularity is partly due to its dazzling interface. In fact, the implementation of those interfaces mainly consists of two main functions: painting transparent images and painting gradient effects. This article mainly describes how to draw transparent images on Windows Mobile.
The so-called transparent image is actually to set the image background to transparent. If you draw an image directly, it will display a regular square image. The image includes an irregular image and the background under the image, therefore, if you only want to draw irregular images, you need to remove the background. The following is the implementation of removing the background.
/// <Summary>
/// Draws the image with transparency
/// </Summary>
/// <Param name = "GX"> Destination graphics </Param>
/// <Param name = "image"> The image to draw </Param>
/// <Param name = "destrect"> Desctination rectangle </Param>
Public static void Drawimagetransparent ( This Graphics GX, Image Image, Rectangle Destrect)
{
Imageattributes Imageattr = New Imageattributes ();
Color Transpcolor = gettransparentcolor (image );
Imageattr. setcolorkey (transpcolor, transpcolor );
GX. drawimage (image, destrect, 0, 0, image. Width, image. height, Graphicsunit . Pixel, imageattr );
Imageattr. Dispose ();
}
Private StaticColorGettransparentcolor (ImageImage)
{
Return((Bitmap) Image). getpixel (image. Width-1, image. Height-1 );
}
Call the bitmap. getpixel () function to retrieve the background information of the image, set the attributes of imageattributes, and pass the image attributes to the graphics. drawimage () function for painting.
As follows:
Some images are not doing well, and they are a little jagged.
The following is an image with no background removed for comparison.