0

I am trying to save bitmaps to an mjpeg file using C#. I can save 1 image as a jpeg with

bitmap.Save("filename", System.Drawing.Imaging.ImageFormat.jpeg);

In the above code, bitmap is an object of type System.Drawing.Bitmap.

I am parsing the images from another file (of custom format) or camera and want to pass them in mjpeg form to WCF. As a first step, I am trying to save mjpeg file.

How to save multiple images in the same file? The file would be using .mjpeg extension instead of .jpeg.

Edit:

Checked Write MJPEG stream to disk but he is trying to save as a memory stream. I want to save it to a mjpeg file.

Community
  • 1
  • 1
user2330678
  • 2,221
  • 14
  • 43
  • 67

1 Answers1

0

You can open a file as a stream using File.Open and then use the approach you're pointing to in order to write the jpg's to that stream. Here's some pseudo code to illustrate:

using (var fileStream = File.Open("movie.mjpg"))
{
    foreach (var bitmap in listOfBitmaps) 
    {
        bitmap.Save(fileStream, Jeg);
    }
}
Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131
  • Do you mean that instead of saving the bitmap as jpeg, I should be creating a file stream? I am parsing the images from another file or camera and want to pass them in mjpeg form to WCF. As a first step, I am trying to save mjpeg file. – user2330678 Aug 15 '14 at 23:12
  • @user2330678 - Hm, there clearly is some confusion here. Are you not able to write the jpg as a stream? ...it would perhaps help if you expand your question with what kind of object your `bitmap` variable is... – Peter Lillevold Aug 15 '14 at 23:16
  • bitmap variable is of type System.Drawing.Bitmap. Edited the question. – user2330678 Aug 15 '14 at 23:25
  • @user2330678 - right, so if you open a file stream, then you can use bitmap.Save to write to the stream instead of directly to a file – Peter Lillevold Aug 15 '14 at 23:37