Problems with ImageColorMode.Grayscale with ImagePixelFormat

Dear sir / madam,

I’m trying to create grayscale TIFF images from images with the Aspose.Words solution (copied from a sample script).

I’ve tried several things to apply the ImagePixelFormat setting. If I set ImageColorMode to None I can adjust the PixelFormat, and I see the properties in the created TIFF file. But if I set it to Grayscale the PixelFormat setting seems to be ignored. It is save as Format32BppArgb each time.

I’ve added my code for my test application.

Am I doing something wrong?

Kind regards,

Toon van Houts

Docspro B.V.

Hi Toon,

Thanks for your inquiry. It seems Aspose.Words always saves a Gray-scaled (uncompressed) Tiff at 32-bit depth. However, I am in communication with our development team to confirm if ImagePixelFormat value can be changed for a Gray-scaled tiff or not. I will update you as soon as I have extra information.

Best regards,

Hi Awais,

is there an update regarding this item?

Hi Toon,

Thanks for being patient. I have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-9961. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi Toon,

Could you please also attach 1) your input Word document, 2) output TIFF file showing the undesired behavior and 3) simplified code to reproduce this issue on our end for testing. We will investigate the issue further on our end and provide you more information.

Best regards,

Hi Awais,

I’m using the Aspose.Words module to convert image files like JPG or multipage TIF files to new TIF files but with color reduction to Black and White or Grayscale. The script I’ve used is (partially) a sample script from the Aspose website.

If I reduce the ImagePixelFormat I see a small difference in filesize of the resulting TIF file but it still is about 18 times bigger (9,05MB) than the original (504kb) JPG file.

Is there an option to reduce the filesize? I want to use the Grayscale option but the filesizes for the output images are now to big. Is there maybe an 8-bit grayscale option?

Sample file: Sample.jpg

Output TIF: True_Grayscale_Lzw_Format16BppRgb555.tif

Script source: Sample script.docx

Hi Toon,

Thanks for your inquiry. The problem occurs because you’re saving to TIFF with horizontal and vertical resolutions as high as 300 dots per inch. You can significantly reduce output TIFF file size by simply specifying 96 value to ImageSaveOptions.Resolution property. I hope, this helps.

Best regards,

Hi Awais,

because the customer wants to store the documents in an ECM system without preserving the hard-copy the minimum required resolution is 300 DPI, decided by our government. That’s why it is configured to create 300 DPI images.

Hi Toon,

Thanks for the additional information. Generally, TIFF files are very large in size compared to JPEGs. When using your code for rendering your JPEG to TIFF format in color mode on my side, Aspose.Words produced a 8,715 KB output. However, rendering to GrayScale color mode did produce a bigger file of size 9,932 KB. I have logged this problem in our issue tracking system as WORDSNET-9971. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi Toon,

Regarding WORDSNET-9971, to decrease size of output Tiff file please use some TiffCompression method. For black and white image use CCIT3 or CCIT4 compression (it produces b&w images only):

ImageSaveOptions mySave = new ImageSaveOptions(SaveFormat.Tiff);

mySave.TiffCompression = TiffCompression.Ccitt4;

For grayscale image there are two ways:

  1. Use Lzw or Rle compression with Grayscale image color mode:
ImageSaveOptions mySave = new ImageSaveOptions(SaveFormat.Tiff);

mySave.ImageColorMode = Aspose.Words.Saving.ImageColorMode.Grayscale;

mySave.TiffCompression = TiffCompression.Lzw;

2. Use CCIT3 or CCIT4 compression with dithering binarization method:

ImageSaveOptions mySave = new ImageSaveOptions(SaveFormat.Tiff);
mySave.TiffCompression = TiffCompression.Ccitt4;
mySave.TiffBinarizationMethod = ImageBinarizationMethod.FloydSteinbergDithering;
mySave.Resolution = 300;

I hope, this helps.

Best regards,

Hi Awais,

as far as there is no 8-bit grayscale option the dithering is the best solution so far. It is no real grayscale but at least the image size is manageable.

Thank you for your help.

Hi Toon,

Thanks for your feedback. Our development team has completed the work on your issue (WORDSNET-9971) and has come to a conclusion to close this issue as ‘Not a Bug’. Please use the solutions suggested in my previous post.

Best regards,

Hi Toon,

Regarding WORDSNET-9961, we have a good news for you i.e. this issue has now been resolved and its fix will be included in Aspose.Words 14.4.0 release which is planned to be published by the end of this month. We will inform you via this thread as soon as the April 2014 release of Aspose.Words is published.

Please note that previously when ImageSaveOptions.ImageColorMode or ImageSaveOptions.ImageBrightness were set to non default values, the output image had always 32BppArgb pixel format. For now ImageSaveOptions.PixelFormat is taken in account, the output image tries to keep that format.

However pixel format of the output image may be changed by GDI+ while saving. The 8bpp is indexed pixel format, and GDI+ has some limitations when working with such format. Since you want to save to 8bpp grayscale image, unfortunately because of GDI+ limitations it is not possible.

Best regards.

The issues you have found earlier (filed as WORDSNET-9961) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.