how can i load jpg from file

  • Thread starter Thread starter user
  • Start date Start date
U

user

Hello
I finally managed to save Bitmap that reprezented my pictureBox to jpg
file, but now how can i load from that file to Bitmap again ?
Bitmap does not have any Load or Open method (like Save...).


Thanx
Michal
 
Hello
I finally managed to save Bitmap that reprezented my pictureBox to jpg
file, but now how can i load from that file to Bitmap again ?
Bitmap does not have any Load or Open method (like Save...).


Thanx
Michal
Hi,

One option is using the constructor to load the file. The Bitmap class
constructor has many overloads and one of it accepts the file name as
parameter.

HTH,
APG
 
Hi Michal,
Hello
I finally managed to save Bitmap that reprezented my pictureBox to jpg
file, but now how can i load from that file to Bitmap again ?
Bitmap does not have any Load or Open method (like Save...).


Thanx
Michal

To load any image you can call:
Image.FromFile(...)

If image if a JPEG then You can cast it to Bitmap.
e.g. Bitmap myJpeg=(Bitmap) Image.FromFile("myJpegPath");

Regards

Marcin
 
Hello
I finally managed to save Bitmap that reprezented my pictureBox to jpg
file, but now how can i load from that file to Bitmap again ?
Bitmap does not have any Load or Open method (like Save...).
Something like this, this prevents locking the file too long.

public void Load(string asFile) {
//--- Because Image keeps th file locked untill the garbage collector
releases it, we have
// to make it released as soon a possible using this trick.
Stream BitmapStream =
System.IO.File.Open(asFile,System.IO.FileMode.Open);
Image imgPhoto = Image.FromStream(BitmapStream);
BitmapStream.Close();

//--- Now the file is beeing released continue using the contents.
mBitmap=new Bitmap(imgPhoto);
}
 

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