By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,291 Members | 3,096 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,291 IT Pros & Developers. It's quick & easy.

Bitmap transparent color not so transparent it seems

P: n/a
Using MakeTransparent one can supposedly turn a color used in a Bitmap to
transparent. But, it looks to me like all it does it set these pixels to the
color BackColor of the Control it's attached to. Thus, when I set White to
the transparent color of a Bitmap stored in the Image of a PictureBox and
placed the PictureBox on a Form which has a BackColor of black, it turned
the white pixels of the bitmap image to black, but these black pixels still
cover anything behind them! At least it seems to cover other PictureBox...

Am I missing something here?
Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi,

I don't know how to fix this problem, but whenever I need transparency
these days I just use .gifs. Besides, it will save you a bit of space
and CPU usage for loading the graphics. I've always used them to keep
things simple.

James

Nov 17 '05 #2

P: n/a
Peter Oliphant wrote:
Using MakeTransparent one can supposedly turn a color used in a Bitmap to
transparent.


Try to use PNG. WinForms supports it and it's truly transparent. In
fact, it supports semi-trasparency (with the alpha channel), which lets
you use really nice looking icons. Also a PNG file is a fraction of a
BMP in size.

Tom
Nov 17 '05 #3

P: n/a
Thanx to both James and Tomas for your replies!!! : )

[==Peter==]

"Tamas Demjen" <td*****@yahoo.com> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl...
Peter Oliphant wrote:
Using MakeTransparent one can supposedly turn a color used in a Bitmap to
transparent.


Try to use PNG. WinForms supports it and it's truly transparent. In fact,
it supports semi-trasparency (with the alpha channel), which lets you use
really nice looking icons. Also a PNG file is a fraction of a BMP in size.

Tom

Nov 17 '05 #4

P: n/a
BTW, I tried using JPG, GIF, and PNG files, and all of them still just
change the color of transparent pixels to the background color of the
control which is it's parent, and do not make them transparent. That is,
they still cover up anything behind them, but appear transparent only if the
background is a solid color and the images are not placed over anything
else, including other such 'sprites' which are suppose to have transparent
parts (which it covers with, for example, black pixels instead of seeing
through them).

This means of course it wil not be transparent at all if one uses a picture
for the background instead of a solid color!

Not that big a deal, but it would be nice to get true transparency. Keep in
mind no matter what the original form (i.e. file type) the image comes from
they all end up as internal Bitmap's in the Image property of a PictureBox,
so transparency must be handled at the Bitmap level (not the file level).

Any clues as to how to get TRUE transparency? : )
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:Of**************@TK2MSFTNGP14.phx.gbl...
Thanx to both James and Tomas for your replies!!! : )

[==Peter==]

"Tamas Demjen" <td*****@yahoo.com> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl...
Peter Oliphant wrote:
Using MakeTransparent one can supposedly turn a color used in a Bitmap
to transparent.


Try to use PNG. WinForms supports it and it's truly transparent. In fact,
it supports semi-trasparency (with the alpha channel), which lets you use
really nice looking icons. Also a PNG file is a fraction of a BMP in
size.

Tom


Nov 17 '05 #5

P: n/a
Peter Oliphant wrote:
BTW, I tried using JPG, GIF, and PNG files, and all of them still just
change the color of transparent pixels to the background color of the
control which is it's parent, and do not make them transparent.


Which component are you using it with? Have you set the control's style
to opaque in the constructor?

SetStyle(ControlStyles::Opaque, true);
// control is drawn opaque and the background is not painted

Also try

SetStyle(ControlStyles::UserPaint, true);
// the control paints itself rather than the operating system doing so
SetStyle(ControlStyles::AllPaintingInWmPaint, true);
// ignores the WM_ERASEBKGND

An example of what you're doing would be nice. When I place a PNG with
an alpha channel on my toolbar, it's not only transparent but fully
translucent, meaning the drop shadow has the color of the background.
The capability is there, it's just that most controls paint themselves,
and they're not designed to be fully transparent.

Tom
Nov 17 '05 #6

P: n/a
Peter Oliphant wrote:
BTW, I tried using JPG, GIF, and PNG files, and all of them still just
change the color of transparent pixels to the background color of the
control which is it's parent, and do not make them transparent.


If it's a PictureBox, may I recommend that you set BackColor to
Transparent? If using the IDE, click on the drop-down arrow, go to the
Web tab, and the first color there is Transparent. To do the same
programmatically:

pictureBox1->BackColor = System::Drawing::Color::Transparent;

Tom
Nov 17 '05 #7

P: n/a
Thanks, Tomas, for responding! : )

Problem is, a line like:

pictureBox1->BackColor = System::Drawing::Color::Transparent;

just changes the BackColor to the specific color that
System::Drawing::Color::Transparent happens to be. That is, if this color is
Black, then it just changes the BackColor of the picture box to black, and
doesn't make it transparent.

What I've been doing is the following:

m_Bitmap->MakeTransparent( trans_color ) ;

Where m_Bitmap is the Bitmap that is pointed to by Image of the PictureBox.
This method is described in the on-line MSDN as:

"Makes the default transparent color transparent for this Bitmap."

But it doesn't. It just displays all of the pixels of color 'trans_color' as
its container's BackColor. Transparency to me means you should be able to
see through the pixel, not just make it a color that will cause it to blend
in with a SOLID COLOR background!

It seems the documentation on this is wrong. I'd love to be wrong instead!
Any ideas? : )

[==P==]

"Tamas Demjen" <td*****@yahoo.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Peter Oliphant wrote:
BTW, I tried using JPG, GIF, and PNG files, and all of them still just
change the color of transparent pixels to the background color of the
control which is it's parent, and do not make them transparent.


If it's a PictureBox, may I recommend that you set BackColor to
Transparent? If using the IDE, click on the drop-down arrow, go to the Web
tab, and the first color there is Transparent. To do the same
programmatically:

pictureBox1->BackColor = System::Drawing::Color::Transparent;

Tom

Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.