I already searched and tried all the suggestions given it at SO, AForge, FreeImage and couple more websites, but I\'m unable to transform an image into a real 8bpp one. I always
UPDATE: The Image.Save()
method does not support 8 bit per pixel for JPEG format. You may want to use the FreeImage library instead, as mentioned in the comments below.
If you want to reduce color depth to 8 bits per pixel, typically that is the same as converting from 24-bit color to grayscale, where each color channel has 8 bits per pixel to begin with. (In other words, reducing 3 channels of color information to 1.)
The default encoder when using Image.Save()
and specifying ImageFormat.Jpeg
is 24 bpp, so you'll need to specify an encoder and supply some parameters:
ImageCodecInfo[] availableCodecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo jpgCodec = availableCodecs.FirstOrDefault(codec => codec.MimeType == "image/jpeg");
if (jpgCodec == null)
throw new NotSupportedException("Encoder for JPEG not found.");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = new EncoderParameter(Encoder.ColorDepth, 8L);
myImage.Save("image_JPEG.jpg", jpgCodec, encoderParams);
This is a modified example from a longer explanation I found at aspnet-answers.com.