Reputation: 5546
i have an algorithm that reduces the number of colors in a picture. I than save the picture with reduced number of colors(32 colors) as jpg. But the new jpg has the same size as the old. Why is this and how can I reduce the size?
Upvotes: 2
Views: 351
Reputation: 86718
A JPEG is always saved with 24-bit color. The JPEG algorithm is designed for saving full-color photographs (that's what the "P" stands for), not reduced-color bitmaps. Reducing the number of colors introduces sharp transitions between colors that use up extra space within the JPEG file.
The proper way to reduce the size of a JPEG is to decrease the quality of the file.
However, it's probably better for you to use a file format that's intended for saving reduced-color images, like PNG or GIF.
Upvotes: 1
Reputation: 700382
The JPEG file format doesn't use a palette, so it still stores all 24 bits of color information for each pixel, even if there are only a few different colors.
You reduce the size of a JPEG image by changing the compression ratio. Higher compression means smaller file size, but also more compression artifacts.
If you want to reduce the file size by reducing the number of colors, you would have to save it using a file format that uses a palette, like GIF or PNG-8.
Upvotes: 4