Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm trying to load an image from a file. I have the following code and get an error. PictFromFile must be Bitmap not Image, because I'm using a function for it that needs a Bitmap as input. Do I need some kind of conversion from Image to Bitmap?? And how is it possible that System.Drawing.Bitmap is Image instead of Bitmap as the name implies?? What is the difference between Image and Bitmap and when should I use which??

 

Bitmap PictFromFile = System.Drawing.Bitmap.FromFile("C:\Pict1.jpg");

 

Error 1 Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?)

Edited by JumpyNET
Posted

Bitmap PictFromFile = System.Drawing.Bitmap.FromFile("C:\Pict1.jpg");

 

try this:

Bitmap PictFromFile = (bitmap)System.Drawing.Bitmap.FromFile("C:\Pict1.jpg");

 

Am not sure if this is going to work. Am installing .NET at the moment so I could not test it. But I will as soon as its instalation finishes...

Posted

I get the following error message:

 

The type or namespace name 'bitmap' could not be found (are you missing a using directive or an assembly reference?)

 

-------------------------------------------

 

This Worked (b --> B):

 

Bitmap PictFromFile2 = (Bitmap)System.Drawing.Bitmap.FromFile("C:\\Pict1.jpg");

 

Thanks!

  • Leaders
Posted

Also note that the Bitmap class has a constructor that accepts a filename. (Less typing is always a plus)


Bitmap PictFromFile2 = new System.Drawing.Bitmap(filename);
[/Code]

[sIGPIC]e[/sIGPIC]
Posted
I get the following error message:

 

The type or namespace name 'bitmap' could not be found (are you missing a using directive or an assembly reference?)

 

-------------------------------------------

 

This Worked (b --> B):

 

Bitmap PictFromFile2 = (Bitmap)System.Drawing.Bitmap.FromFile("C:\\Pict1.jpg");

 

Thanks!

are you using the reference "using System.Drawing"? (at the very begin of your code)

 

Well if not and if you for some reason do not wish to, write it like this:

Bitmap PictFromFile2 = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("C:\\Pict1.jpg");

 

But also, like Marble eater suggested, try using the "new" keyword instead...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...