How to: Convert Bitmap to Image?

  • Thread starter Danyel Meyer - dialog-it GmbH
  • Start date
D

Danyel Meyer - dialog-it GmbH

Hallo!

When using OpenNetCF´s ButonEx I´d like to put transparent images onto them.
I have created a function that fakes transparency of a given Image-object
and returns a Bitmap-object.
The ButtonEx of the SDF only accepts Image-objects for its Image-attribute,
so how do I convert a Bitmap-object to an Image-object?

Thanks in advance,

--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
P

Peter Foot [MVP]

Since Bitmap inherits from Image you can assign it to the Image property of
ButtonEx.

Bitmap bmp = new Bitmap("somefile.gif");
buttonEx1.Image = bmp;

Peter
 
D

Danyel Meyer - dialog-it GmbH

Thanks Peter, but that is what I have tried, and it does not work. I get an
"Not supported" exception on it... thats why I asked ;)


--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
D

Danyel Meyer - dialog-it GmbH

Well, ok...

It needs something like the following to work:

buttonEx1.Image = New Bitmap(myFunction(New Bitmap(the Image),
Color.WhatEver))

Thanks Peter ;)


--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
C

Chris Tacke, eMVP

It should work, but maybe try to explicitly cast it:

Bitmap bmp = new Bitmap("mypic.bmp");
buttonex1.Image = (Image)bmp;

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top