How do I create a Stream object from a Bitmap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Fuller

    How do I create a Stream object from a Bitmap

    I have a need to write a Bitmap to a Stream, but get an error message on all
    my attempts. I am doing something like the following:

    Stream _appImage;

    public frmCustomerFeed back(Bitmap bm)
    {
    InitializeCompo nent();

    bm.Save(_appIma ge, System.Drawing. Imaging.ImageFo rmat.Jpeg); <== this
    fails
    //bm.Save("testim g.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg); <==
    this works
    ugPictureBox.Im age = bm;
    }

    Any suggestions?


  • Peter Duniho

    #2
    Re: How do I create a Stream object from a Bitmap

    On Mon, 03 Nov 2008 16:33:27 -0800, Bill Fuller <someone@nospam .comwrote:
    I have a need to write a Bitmap to a Stream, but get an error message on
    all
    my attempts. I am doing something like the following:
    >
    Stream _appImage;
    >
    public frmCustomerFeed back(Bitmap bm)
    {
    InitializeCompo nent();
    >
    bm.Save(_appIma ge, System.Drawing. Imaging.ImageFo rmat.Jpeg); <==
    this fails
    //bm.Save("testim g.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg);
    <== this works
    ugPictureBox.Im age = bm;
    }
    >
    Any suggestions?
    Yes. Initialize your _appImage variable so that it actually references an
    instance of the Stream class.

    Just as the documentation promises, if you pass "null" for that argument
    (or the second, for that matter), you'll get an ArgumentNullExc eption.

    So: don't pass null. How can the method know what Stream to write to if
    you don't pass it a valid reference to one?

    Pete

    Comment

    • Bill Fuller

      #3
      Re: How do I create a Stream object from a Bitmap

      Never mind... found my problem.

      MemoryStream _appImage = new MemoryStream();


      "Bill Fuller" <someone@nospam .comwrote in message
      news:%23GVH1ThP JHA.4008@TK2MSF TNGP02.phx.gbl. ..
      >I have a need to write a Bitmap to a Stream, but get an error message on
      >all my attempts. I am doing something like the following:
      >
      Stream _appImage;
      >
      public frmCustomerFeed back(Bitmap bm)
      {
      InitializeCompo nent();
      >
      bm.Save(_appIma ge, System.Drawing. Imaging.ImageFo rmat.Jpeg); <== this
      fails
      //bm.Save("testim g.jpg", System.Drawing. Imaging.ImageFo rmat.Jpeg); <==
      this works
      ugPictureBox.Im age = bm;
      }
      >
      Any suggestions?
      >

      Comment

      Working...