Transparency problem drawing bitmap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Hoffer

    Transparency problem drawing bitmap

    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.ImageAt tributes imageAttributes = new
    System.Drawing. Imaging.ImageAt tributes();

    imageAttributes .SetColorKey(Co lor.FromArgb(23 1, 231, 231),
    Color.FromArgb( 231, 231, 231), ColorAdjustType .Bitmap);

    Point ulCorner1 = new Point(0, 0);

    Point urCorner1 = new Point(GetBitmap Size().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.Smoo thingMode = SmoothingMode.H ighQuality;

    e.Graphics.Inte rpolationMode = InterpolationMo de.HighQualityB icubic;

    e.Graphics.Pixe lOffsetMode = PixelOffsetMode .HighQuality;

    e.Graphics.Draw Image(m_Selecte dImage, destPara1, srcRect,
    GraphicsUnit.Pi xel, 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


  • 100

    #2
    Re: Transparency problem drawing bitmap

    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

    "David Hoffer" <dhoffer.remove @xrite.remove.c om> wrote in message
    news:ux0BbKV1DH A.4032@tk2msftn gp13.phx.gbl...[color=blue]
    > 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.ImageAt tributes imageAttributes = new
    > System.Drawing. Imaging.ImageAt tributes();
    >
    > imageAttributes .SetColorKey(Co lor.FromArgb(23 1, 231, 231),
    > Color.FromArgb( 231, 231, 231), ColorAdjustType .Bitmap);
    >
    > Point ulCorner1 = new Point(0, 0);
    >
    > Point urCorner1 = new Point(GetBitmap Size().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.Smoo thingMode = SmoothingMode.H ighQuality;
    >
    > e.Graphics.Inte rpolationMode = InterpolationMo de.HighQualityB icubic;
    >
    > e.Graphics.Pixe lOffsetMode = PixelOffsetMode .HighQuality;
    >
    > e.Graphics.Draw Image(m_Selecte dImage, destPara1, srcRect,
    > GraphicsUnit.Pi xel, 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()[/color]
    was[color=blue]
    > supposed to do this.
    >
    >
    >
    > -dh
    >
    >[/color]


    Comment

    Working...