Transparency problem drawing bitmap

  • Thread starter Thread starter David Hoffer
  • Start date Start date
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
 
you need to add the alpha channel so the color should be
something like

Color c=new Color (125,231,231,231);

thus you will get a transparent color

-----Original Message-----
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
 
Back
Top