I'm having a strange problem - I have about 14.5 million bitmap images, that are supposedly uncompressed. I need to convert these bitmaps to JPG and store them in a database.
When I use the classes provided in the .NET System.Drawing library to save the bitmap as a ImageFormat.Jpeg, the resulting JPEG is about 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 have looked through the HEX of several of these images, and it looks like the compression setting is "none". So I'm assuming they are uncompressed. Additionally, the HEX for the original file has the "BMP" code and the resulting file has the "JFIF" code as you would expect.
The images are black and white, no colors.
Any thoughts as to why this would be happening? Looking for pointers in the right direction...
Edits:
- I've tried using the alternate overload to save that allows you to specify the quality. No benefit seen.
- I should also specify that I'm kind of stuck with JPEG to some degree here. This is a legacy system and other parts of the system expect JPEG.
Image attributes:
- Bitmap dimensions: 152x48
- Bitmap file size: 1022 bytes
- JPEG: same dimension
- JPEG size: 2.2 kb
- Bitmap info: Indexed, 1 layer (2 colors)
- Bitmap resolution: 96.012x 96.012 ppi