How to use. NET Compact framework to draw transparent images on Windows Mobile

Source: Internet
Author: User
Tags transparent image

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.