Image.FromFile

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi,
I'm having problems adding pictures to an imagelist using a filename in my
working directory. Heres the code i'm trying use -
myImageList.Images.Add(System.Drawing.Image.FromFile("tree1.gif"));

I get complaints about using from file i guess its because it does not
exist for the compact framework, is there another way of doing the same
thing.

Thanks,

Paul
 
Use a constructor overload for the Bitmap class:
Bitmap bmp = Bitmap("tree1.gif");
myImageList.Images.Add(bmp);
 
Don't be like me and forget the "new" :)
Bitmap bmp = new Bitmap("tree1.gif");
 
Also keep in mind that CE has no notion of a "working directory". It's all
absolute based. Using no path or slash may correctly load it from the
directory your app is in, but it's far safer to either hardcode the full
path or find the path of the executing assembly and preface the file name
with it.

-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

Back
Top