473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.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
Nov 15 '05 #1
1 4923
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

"David Hoffer" <dh************@xrite.remove.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
20
by: Nathan Sokalski | last post by:
I am trying to create graphics with GDI+ that include transparency. However, the transparency never seems to show up, even though my colors have an alpha value of 0. How can I generate a graphic...
6
by: tommaso.gastaldi | last post by:
In a previous post I have been asking about a way to test Alpha Transparency. Bob and Michael have kindly provided some ideas. Here I would like to share the function I have prepared, for the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.