2

In my program, I compress a BMP into a JPEG like this:

private void ConvertBmpToStreamJPG30(Bitmap b, Stream s)
{
  s.Flush();
  EncoderParameters encoderParameters = new EncoderParameters(1);
  encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 30L);
  b.Save(s, GetEncoder(ImageFormat.Jpeg), encoderParameters);
}

Then a function is receiving the JPEG in a MemoryStream, I transform it into a Bitmap by doing

Bitmap b = new Bitmap(stream);

When I display the image, there are a lot of lines like this :

Screenshot

What am I doing wrong, people?

Edit 1 Here a small visual studio solution showing the problem: http://www.fast-files.com/getfile.aspx?file=79311

It is the beginning of a screen sharing software. What it does: It takes screenshots, compare them, compress the difference and send it to another part of the program that decompress it and recompose an image with everything received. It opens a window displaying what is "sent" on the left and the recomposed image on the right.

Poutchyouk
  • 33
  • 4

1 Answers1

0

Three things come to mind:

  1. Try setting a better quality than 30 and see if that helps;
  2. Check your RAM (and possibly video RAM, though I doubt that GDI+ might use VGA for compression) for hardware problems;
  3. I've had a similar weird problem where I loaded some JPEG file, modified it a bit, and then saved it again. That produced an exception. The solution was to make a new bitmap based on the old one and save the copy. Try that.
Community
  • 1
  • 1
Vilx-
  • 104,512
  • 87
  • 279
  • 422