image color transparency

  • Thread starter Thread starter newbie_csharp
  • Start date Start date
N

newbie_csharp

Hi,
I need to load a picture on a button but I'd like to set white color
tranansparency (not to show white color). How can I do it? I tried to
load a masked color GIF file but VS 2002 could not load it.

thanks
 
Why don't you just create your gif with a transparency layer and put the
transparent gif on the button? That should work.

- Peder -
 
newbie_csharp said:
I need to load a picture on a button but I'd like to set white color
tranansparency (not to show white color). How can I do it? I tried to
load a masked color GIF file but VS 2002 could not load it.

Does the Bitmap class's 'MakeTransparent' method do what you need?

E.g.

Bitmap bmp = new Bitmap("MyGifFile.gif");
bmp.MakeTransparent(Color.White);
btn.BackgroundImage = bmp;
 
Hi Peder,
I opened a gif file in Corel and saved it with setting white color
transparency; but in Visual Studio I could not open it. it didn't let me to
open those kind of Gif files. I am using VS 2002 right now.
thanks,
Hamid
 
Hi Ian,

thanks a lot. that worked. but should I do the same for all my buttons? is
there any simpler way for doing this? but this answer helped me learn about
Bitmap :) thanks Ian!

Hamid
 
When you say you're looking for something simpler, do you mean you want
simpler code? (I didn't think 3 lines of code was all that bad...) Or do
you want to do without code at all, and instead go via the designer?

I think I'd need to understand a little more about what you're doing before
I can suggest what might make it simpler.

--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

Adine said:
thanks a lot. that worked. but should I do the same for all my buttons? is
there any simpler way for doing this? but this answer helped me learn
about Bitmap :) thanks Ian!
 
I meant via designer. because if I have 20 buttons on the form, then I need
to add 20 x 3 lines in the program. that would be nice if VS had a property
beside image property to set the transparency.

Thanks again

Ian Griffiths said:
When you say you're looking for something simpler, do you mean you want
simpler code? (I didn't think 3 lines of code was all that bad...) Or do
you want to do without code at all, and instead go via the designer?

I think I'd need to understand a little more about what you're doing
before I can suggest what might make it simpler.
 
Something you could try is writing a little program to load all your button
GIF files, doing the MakeTransparent thing and then saving them back out as
PNG files, and then loading them in via the designer.

I don't know if that would actually work by the way, I'm just hypothesizing
that it might - I'd try it with one file on its own first... Something like
this:

Bitmap bmp = new Bitmap("MyGifFile.gif");
bmp.MakeTransparent(Color.White);
bmp.Save("MyFile.png", Imageformat.Png);

See if loading that PNG file in with the designer now works as intended.
(I'm suggesting this because PNG supports a full alpha channel.)

If that seems to work, then just convert all the GIFs to PNGs using code
like the above as a once-off process, and then use the PNGs as the things
you load into the designer.
 
perfect! PNG type was the answer. that's great. now I don't need to load the
image all the time and set the transparency.

Thank you so much, Ian.
 
Hi Adine!

I see Ian solved your problem. Glad you worked it out. However, I've
never had problems using transparent gif's. It could be that VS don't
support the gif format Corel produces. My Photoshop exports Gif89a,
which is the ancient gif standard. This seems to work fine. Good luck!

- Peder -
 
Hi Adine!

I see Ian solved your problem. Glad you worked it out. However, I've
never had problems using transparent gif's. It could be that VS don't
support the gif format Corel produces. My Photoshop exports Gif89a,
which is the ancient gif standard. This seems to work fine. Good luck!

- Peder -
 
Back
Top