Error message: Only 24-bit true color bmp and 8-bit gray-scaled image are supported for JPEG compression

Symptom:

When you save or upload an image as a JPEG file, you may receive the following error message:

Only 24-bit true color bmp and 8-bit grayscale images are supported for JPEG compression.

Cause:

You are saving a Black&White image as a JPEG file. JPEG standard only allows the compression of grayscale and RGB images.

Resolution:

Please make sure the pixel type of the image in buffer is Gray or RGB. You can set the value of pixel type by using the PixelType property.

Or, you can convert the image to grayscale using the method ConvertToGrayScale.

Javascript Code:

if (/*If save in JPEG*/) {
    //If the current image is B&W
    //1 is B&W, 8 is Gray, 24 is RGB
    if (DWObject.GetImageBitDepth(DWObject.CurrentImageIndexInBuffer) == 1)
        //If so, convert the image to Gray
        DWObject.ConvertToGrayScale(DWObject.CurrentImageIndexInBuffer);
    //Save image in JPEG
    DWObject.SaveAsJPEG("DynamicWebTWAIN.jpg", DWObject.CurrentImageIndexInBuffer);
}

Reference:

PixelType
SaveAsJPEG()
GetImageBitDepth()

Is this page helpful?

Leave a Reply

Your email address will not be published.