Transparency problem drawing bitmap

D

David Hoffer

I am creating a custom user control and I am having problems with setting
the transparent color of the bitmap. Here is my code...

protected override void OnPaint( PaintEventArgs e )

{

System.Drawing.Imaging.ImageAttributes imageAttributes = new
System.Drawing.Imaging.ImageAttributes();

imageAttributes.SetColorKey(Color.FromArgb(231, 231, 231),
Color.FromArgb(231, 231, 231), ColorAdjustType.Bitmap);

Point ulCorner1 = new Point(0, 0);

Point urCorner1 = new Point(GetBitmapSize().Width, 0);

Point llCorner1 = new Point(0, GetBitmapSize().Height);

Point[] destPara1 = {ulCorner1, urCorner1, llCorner1};

Rectangle srcRect = new Rectangle( 0, 0, GetBitmapSize().Width,
GetBitmapSize().Height);

e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

e.Graphics.DrawImage(m_SelectedImage, destPara1, srcRect,
GraphicsUnit.Pixel, imageAttributes);

}

I want the specified RGB color (231, 231, 231) to be transparent, but it
isn't. What am I doing wrong? I thought imageAttributes.SetColorKey() was
supposed to do this.



-dh
 
1

100

Hi David,
Your code works for me. Are you sure about the rgb components of the color
you want to make transparent.
Do you have such a color in your image.

B\rgds
100
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top