Transparency

  • Thread starter Thread starter Floyd Burger
  • Start date Start date
F

Floyd Burger

How do you get a transparency when using a Graphics? On the regular
framework, you can change the Alpha part of a Color to change the
transparency, but Alpha is not available on the Compact Framework. Thanks.

--
 
You can use the override of DrawImage which takes an ImageAttributes
argument - this allows you to specify a colour in the image to ignore when
drawing hence leaving the specified area transparent.
Windows CE does not support alpha-blending like Windows XP and similar do so
all colours are considered opaque.

Peter
 
Search the archives. There's plenty of history on the subject. Elisa will
surely make a note as well.

-Chris
 
Hi Chris,

Don't tempt me! ;-)

I'm actually not sure if Floyd is even asking about transparent bitmaps.
If you simply want to draw lines, boxes, etc. with a translucent effect,
you can "fake" translucency yourself by using interpolation:

Rnew = R2 + (((R1 - R2) / 255) * alpha)
Gnew = G2 + (((G1 - G2) / 255) * alpha)
Bnew = B2 + (((B1 - B2) / 255) * alpha)

E.g. if you have a yellow background (R=255, G=255, B=0), and want to
overlay a purple rectangle (R=255, G=0, B=128) with 75% alpha (0% =
opaque, 100% = transparent), you'd need to calculate the color as follows:

Rnew = 255 + (((255 - 255) / 255) * ((75 * 255) / 100))
Gnew = 0 + (((255 - 0) / 255) * ((75 * 255) / 100))
Bnew = 128 + (((0 - 128) / 255) * ((75 * 255) / 100))

or

Rnew = 255
Gnew = 191
Bnew = 32


Regards,

Elisa
 
Floyd,

If this is indeed what you are after, and you don't mind unsafe code blocks,
then you can check out my sample using GAPI that supports alpha blending
(translucency), as well as source and destination color key transparency for
bitmaps, lines, points, and filled rectangles. It is quite a bit faster
than GDI.

Dancing Particles: Adding Points, Lines, Fonts, and Input to the Managed
Graphics Library
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/WrapGAPI3.asp

Also, here is a FAQ item with a sample if you want to do what Chris
described:

2.4. How do I draw an image with transparency?
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx#2.4

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top