how can i load jpg from file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • user@domain.invalid

    how can i load jpg from file

    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

  • APG

    #2
    Re: how can i load jpg from file

    user@domain.inv alid wrote:
    [color=blue]
    > 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
    >[/color]
    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

    Comment

    • Marcin Grzêbski

      #3
      Re: how can i load jpg from file

      Hi Michal,
      [color=blue]
      > 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[/color]

      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

      Comment

      • Guest's Avatar

        #4
        Re: how can i load jpg from file

        > Hello[color=blue]
        > 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...).
        >[/color]
        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,Sys tem.IO.FileMode .Open);
        Image imgPhoto = Image.FromStrea m(BitmapStream) ;
        BitmapStream.Cl ose();

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


        Comment

        Working...