Why are JPEG images created with System.Drawing larger than original bitmaps?

I have a strange problem: I have about 14.5 million bitmaps that are supposedly uncompressed. I need to convert these bitmaps to jpg and save them in a database.

When I use the classes provided in the .NET System.Drawing library to save the bitmap as ImageFormat.Jpeg, the resulting JPEG is twice the size of the original bitmap. Here is the code:

byte[] bitmapBytes = //get from the db
using(MemoryStream bitmapStream = new MemoryStream(bitmapBytes))
{
   using(Bitmap bitmap = (Bitmap)Bitmap.FromStream(bitmapStream))
   {
       bitmap.Save("jpg.jpg", ImageFormat.Jpeg);
   }
}

I looked at the HEX of several of these images, and it looks like the compression parameter is "none". Therefore, I assume that they are uncompressed. In addition, the HEX for the source file has the code “BMP”, and as a result, the file has the code “JFIF”, as you would expect.

Images are black and white, without colors.

Any thoughts on why this is happening? Searching for pointers in the right direction ...

Changes:

  • I tried using an alternative overload to save, which allows you to specify quality. No benefit is visible.
  • I should also point out that I'm stuck in JPEGs to some degree. This is an outdated system, and other parts of the system expect JPEG.

Image Attributes:

  • Raster Image Size: 152x48
  • Bitmap file size: 1022 bytes.
  • JPEG: same measurement
  • JPEG size: 2.2 kb
  • : , 1 (2 )
  • : 96.012x 96.012 ppi
+3
9

, - , jpeg, , 24- RGB, - 1 bpp - .

1 , jpeg, , .

+6

- ?

http://www.faqs.org/faqs/compression-faq/part2/section-6.html:

"JPEG , - , bilevel (-) , , . ; . JPEG . ".

+4

Bitmap.Save, EncoderParameter.

, , , BMP ( 24-) .

+2

2- 61x64:

  • -4 tiff: 268
  • 2 color bmp ( ): 550
  • 8 jpeg: 1502
  • 32- jpeg ( System.Drawing create): 2015

, jpegs, 8 . .Net , , CodeProject .

+2

. PNG, PNG 1 -. .

, , JPG .

+1

( JPEG) , ImageCodecInfo EncoderParameters

0

: , JPEG. JPG? , - - , BMP .

, Windows BMP JPG, , Windows .

0

Source: https://habr.com/ru/post/1707697/


All Articles