Free Support Forum - aspose.com

Convert 1bit Black & White Image to 8 Bit Grayscale renders white color to lightgray #FCFCFC

Aztek_binary.png (2.1 KB)
1015865824_QRCODE.png (2.1 KB)

Code used:

using (PngImage png2 = Aspose.Imaging.Image.Load(ms) as PngImage)
 {
         PngOptions options1 = new PngOptions();
         options1.ColorType = PngColorType.Grayscale;
         //options.CompressionLevel = 0;
         options1.BitDepth = 1;

         options1.BitDepth = 8;
         png2.Save(qrDestinationFilePath, options1);
         }

When I use the color-pipete-tool the white parts of the image are #FCFCFC (light-gray) insted of #FFFFFF (white)

@Markus1980Wien

I have created a ticket with ID IMAGINGNET-4321 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

@Markus1980Wien

We have investigated code that you assumes to be wrong. But it is not at all. Provided code works as expected, ie when specify 8 bits in grayscale it means will be presented 2 power 8 colors. Here is code that you may use to be presented only black and white colors:

using (Aspose.Imaging.FileFormats.Png.PngImage image =
(Aspose.Imaging.FileFormats.Png.PngImage)Image.Load(@"Aztek_binary.png"))
{
Aspose.Imaging.ImageOptions.PngOptions options1 = new Aspose.Imaging.ImageOptions.PngOptions();
options1.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale;
options1.BitDepth = 1;
image.Save(@"Aztek_binary_out.png", options1);
}

Also I’ve attached output file and checked that it contains only 2 colors.
Aztek_binary_out.png (2.6 KB)

Maybe I did not express myself correct.

Take the binary black and white image named Aztek_binary.png and convert it to an 8-bit gray-scale image using the code provided.
After you have converted the image to 8-bit-grayscale image, open this new image with an ImageViewer like “paint.net.” Take the color-picker tool and you will see that the image is composed of two different colors.
One color is Black (R: 0; G: 0 B:0 or hex 000000)
The other color is light-gray (R: 252, G: 252, B:252 or hex FCFCFC) .

BUT:
the other color should be White (R: 255, G: 255; B: 255 or hex FFFFFF.

So when saving a bitonal black and white-image as 8-bit-grayscale image, the colors in the image change from black and white, to black and lightgray.

@Markus1980Wien

Thank you for your feedback and I have associated the information in our issue tracking system for further investigation on our end. We will share feedback with you as soon as the issue will be addressed.

@Markus1980Wien

We have opened resultant image in Paint.NET and picked a color and as you can see we have white color not light-gray. We have tested it in with latest Aspose.Imaging for .NET 21.2 on our end and in our opinion in tiyr code there is possible error. There are two lines

options1.BitDepth = 1;
options1.BitDepth = 8;
But he needs only
options1.BitDepth = 1;

So correct code is:

using (PngImage png2 = Aspose.Imaging.Image.Load(ms) as PngImage)
{
    PngOptions options1 = new PngOptions();
    options1.ColorType = PngColorType.Grayscale;
    options1.BitDepth = 1;
    png2.Save(qrDestinationFilePath, options1);
}

responseForCustomer.png (73.0 KB)