title: Bitmap from Stream: Bug?
body: <p>I have a pretty strange Error. I need to scale down images, scale down the quality and convert to JPEG. This all works when I save the File on disk, but it doesn't work when I save it to a Stream.</p>
  
  <pre><code>System.Drawing.Bitmap bitmap = // valid Bitmap from Disk
  System.IO.Stream stream = new MemoryStream();
  
  // JPEG Encoding
  
  System.Drawing.Imaging.ImageCodecInfo jpgEncoder = GetEncoder( System.Drawing.Imaging.ImageFormat.Jpeg );
  System.Drawing.Imaging.Encoder encoder2 = System.Drawing.Imaging.Encoder.Quality;
  System.Drawing.Imaging.EncoderParameters parameters = new System.Drawing.Imaging.EncoderParameters( 1 );
  System.Drawing.Imaging.EncoderParameter parameter = new System.Drawing.Imaging.EncoderParameter( encoder2, qualityLevel );
  parameters.Param[0] = parameter;
  
  // Save downscaled on Disk and stream
  
  bitmap.Save( stream, jpgEncoder, parameters );
  bitmap.Save( @"C:\TestJPEG.jpg", jpgEncoder, parameters );
  
  // some stream stuff
  
  var bytes = ((MemoryStream)stream).ToArray();
  System.IO.Stream inputStream = new MemoryStream( bytes );
  
  // Load from disk and stream
  
  Bitmap fromDisk = new Bitmap( @"C:\TestJPEG.jpg" ); // works
  Bitmap fromStream = new Bitmap( inputStream ); // crash invalid parameter no inner message or description
  Bitmap fromStream2 = (Bitmap)Bitmap.FromStream( inputStream ); // same error here
  // also crashes if I load the "stream" named Stream
  </code></pre>
  
  <p>I can also open the converted file with Paint. 
  Any suggestions?</p>
  
  <p><strong>Edit:</strong>
  I'm using .Net Framework 4.0 on Windows 7 Professional</p>
  
  <p><strong>Edit2:</strong>
  Tried that Seek thing (Answer was deleted)</p>
  
  <pre><code>stream.Seek( 0, SeekOrigin.Begin );
  </code></pre>
  
  <p>It workes with the "old" stream. But i need to load it from a byte Array. Still same crash</p>