WM achieves transparent Effect

Source: Internet
Author: User

1. Use the AlphaBlend API. This can be seen in instructor Li's article. See original article

Reprinted below:

The. NET Framework WinForm program supports adjusting the transparency of controls and GDI +. It can be used to achieve a cool interface effect such as fade in and out. However. NET Compact Framework forms and controls do not support transparency and GDI +, so images are often used to complete some beautiful program interface effects, this will increase the size of the package with a lot of alternate images.

Today, we can see Alpha Blend APIs on Windows Mobile 5.0/6, which can be used to implement some transparent controls, as shown in:

 

Why?

The demo program above comes from the open-source project of AlphaMobileControls. AlphaMobileControls provides some simple controls that can achieve transparent effects, such as AlphaLabel, AlphaPictureBox, and AlphaImageButton, they must be placed on a special AlphaPanel or AlphaForm container control. This control is implemented by encapsulating the Imaging API and AlphaBlend () API functions provided by Windows Mobile 5.0 and cannot be used in Windows Mobile 2003 programs. In addition, users who use C/C ++ can also refer to related APIs to achieve this transparent effect.

For the implementation of Windows Mobile Alpha Blend details, you can refer to this article: http://blogs.msdn.com/chrislorton/archive/2006/04/07/570649.aspx

In addition, there is also a method to implement transparent control background. Using C/C ++ and API to draw a control using the Pattern Brush that draws the background, the effect is as follows:

Here no more introduction, you can see the original: http://www.codeproject.com/KB/mobile/transparent_controls.aspx

 

Ii. SetColorKey for Transparency

For the original article, see MSDN How to: Draw Images with Transparency.

Implementation Method: when rendering, extract the specified color from the bitmap to achieve transparent effect:

The first step is to build the color key to be masked during rendering ). We need to specify an exact color key value instead of a range.

1 ImageAttributes imgattr = new ImageAttributes ();
2imgattr. SetColorKey (Color. Red, Color. Red );
3 // imgattr. setColorKey (Color. fromArgb (255, 0, 0), Color. fromArgb (255, 0, 0); // if you do not want to use the standard Color provided in the Color class, set the Color value in RGB mode
4 // imgattr. SetColorKey (bmp. GetPixel (), bmp. GetPixel (); // or directly use the pixel value
5
6 // prepare and draw the picture below
7 Rectangle dstRect = new Rectangle (0, 0, bmp. Width, bmp. Height );
8e. Graphics. DrawImage (bmp, dstRect, 0, 0, bmp. Width, bmp. Height,
9GraphicsUnit. Pixel, attr );

 

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.