473,398 Members | 2,335 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,398 software developers and data experts.

Bitmap transparent color not so transparent it seems

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
7 3542
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Flo | last post by:
Hi, I'm trying to develop a COM interface in C# that would provide a bitmap handle. In that DLL i do have a Bitmap object and i'm using the GetHbitmap method to create a new similar bitmap and...
2
by: Jax | last post by:
So far i've not had much luck with this method. Bitmap.MakeTransparent(someColor); Makes the transparent colour either a non-transparent black (.bmp, jpg or .gif) or silver (.png) i've tried...
2
by: Carl Gilbert | last post by:
Hi I have to following code which sets up a new bitmap. 'set up a transparent 16x16 bitmap Dim bm As New Bitmap(16, 16) Dim g As Graphics = Graphics.FromImage(bm)...
2
by: Dennis | last post by:
I have created a bitmap and set the transparency color to black; mybitmap.MakeTransparent(Color.Black) myicon = Icon.FromHandle(bm.GetHicon) This creates the icon ok but the background color...
3
by: Dennis | last post by:
I have a bitmap and make the color transparent; mybitmap.MakeTransparent(Color.Black) When I save it as a Icon, the black color is not transparent. However, if I save it as a bitmap then...
2
by: Sharon | last post by:
Hello Experts, I'm creating a bitmap object like this: Bitmap myImage = new Bitmap(1024, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb); But when I invoking the function myImage...
2
by: Dennis | last post by:
I have about 50 images in my application as "embedded resources". They are Icon size (16x16 and 24x24 and 32x32). I can use either the bitmap version or convert them to Icons. Either way seems...
5
by: Dale | last post by:
When I create a System.Drawing.Bitmap and save it as ImageType.GIF, how can I set the transparency so that the background is transparent. In my application, the Bitmap that I am working with has...
3
by: NickP | last post by:
Hi there, I have a usercontrol that inherits from Windows.Forms.Button. In the OnCreateControl method I set the style of the control so that it supports transparent backcolor and set the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.