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 a image in buffer as a JPEG file, you may receive the following error message:

Cause:

You are saving a Black&White image as a JPEG file. JPEG standard defines that only 256 gray-scaled image and 24 bit RGB image can be compressed as JPEG format.

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 Dynamic Web TWAIN's PixelType property.

Or, you can convert the image to Gray for saving by 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
HTTPUploadThroughPost()
SaveAsJPEG()
GetImageBitDepth()

Is this page helpful?

Leave a Reply

Your email address will not be published.