Compact Transparency

I need to create an image with a transparent background in .NETCF, I use a magenta background as the background that I want to make transparent. The way I tried to do this is to override onPaint (). But I can’t get the background transparent? Here is what I have:

protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; ImageAttributes imageAttributs = new ImageAttributes(); imageAttributs.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255)); g.DrawImage(cross, crossRect, 200, 10, cross.Width, cross.Height, GraphicsUnit.Pixel, imageAttributs); base.OnPaint(e); } 

But when I try to enable ImageAttributes, is my image not drawn at all?

+6
c # windows-mobile compact-framework
source share
3 answers

Ah, transparency in CF. Hours and days can (and did) be spent on it. Firstly, you can give us a little more information about the images you use (bitmap images, png, etc.), but we can probably get a little out of your message. We also need to know if this is in the child container (e.g. inside the frame, panel, etc.).

Colorkey's transparency is certainly supported (it was from 2.0 - maybe even earlier). The problem here is that you get the parent "bleed out" if you have a child. This is similar to what you are trying, but it is not entirely obvious to me, so I have a few follow-up questions for clarification.

  • Is an override of the OnPaint form or user control?
  • Why do you call base OnPaint () after your work (unlike before or not at all)?
  • Have you redefined OnPaintBackground?

My guess right now is that you have a mistake in how you call everything, but we don’t have enough code to define it.

Here are some more resources on painting and transparency:

There are more resources for the alpha channel (this is far from easy in CF), but since it looks like you're trying to colorkey, that should be enough.

+9
source share

The compact structure does not support transparency - you can achieve its support through COM interoperability. Chris Lorton has a very good blog post about alpablending on a compact basis.

+3
source share

It looks like OpenNETCF is already wrapping a wrapper around this. I'm sure Chris Takee could comment on this. He seems to be pretty active on this site, but seems to have beaten him before that :)

+1
source share

All Articles