Alpha blending colors in .NET Compact Framework 2.0

In the Full .NET framework you can use the Color.FromArgb() method to create a new color with alpha blending, like this:

Color blended = Color.FromArgb(alpha, color);

or

Color blended = Color.FromArgb(alpha, red, green , blue);

However in the Compact Framework (2.0 specifically), neither of those methods are available, you only get:

Color.FromArgb(int red, int green, int blue);

and

Color.FromArgb(int val);

The first one, obviously, doesn't even let you enter an alpha value, but the documentation for the latter shows that "val" is a 32bit ARGB value (as 0xAARRGGBB as opposed to the standard 24bit 0xRRGGBB), so it would make sense that you could just build the ARGB value and pass it to the function. I tried this with the following:

private Color FromARGB(byte alpha, byte red, byte green, byte blue)
{
    int val = (alpha << 24) | (red << 16) | (green << 8) | blue;
    return Color.FromArgb(val);
}

But no matter what I do, the alpha blending never works, the resulting color always as full opacity, even when setting the alpha value to 0.

Has anyone gotten this to work on the Compact Framework?


显然,它不是那么简单,但仍然可能,如果你有Windows Mobile 5.0或更新版本。


Apparently, it's not quite that simple, but still possible, if you have Windows Mobile 5.0 or newer.

Wow...definitely not worth it if I have to put all that code in (and do native interop!) Good to know though, thanks for the link.


在那里有一个codeplex站点,似乎为你做了繁重的com互操作:

链接地址: http://www.djcxy.com/p/53690.html

上一篇: 在.Net中使用ScrollBars

下一篇: Alpha Compact Framework 2.0中的Alpha混合颜色