Incorrect default back color for transparent images

Hello
Load a transparent png file:
A.png (2.0 KB)

And save as Tiff with TiffExpectedFormat.TiffDeflateRgb (without transparency)
The alpha channel is painted by default black which seems wrong and should be white.
At least all apps I know are using white as default.
Now, the transparent area is colored black, applies to other formats :frowning:

2, using TiffExpectedFormat.TiffDeflateBw will make invalid images, most colors are lost, use it with the above sample image and see the result.

  1. Save the above image as Gif with HasTransparentColor = True and see the black border line around the edges, if set to False, the whole back color is again black!

@australian.dev.nerds , we will process your question and answer.

@australian.dev.nerds
For case #2 to keep details in BW image try using the next code example, as turning Color to BW leads to inevitable color loss:

var inputPath = @"A.png";
using (var image = Image.Load(inputPath) as PngImage)
{
    // use dithering to improve color transferring to BW
    image.Dither(DitheringMethod.FloydSteinbergDithering, 1);
    image.Save(inputPath + ".tiff", new TiffOptions(Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.TiffDeflateBw));
}

For case #3 Gif with transparency try using the next code example:

var inputPath = @"A.png";
using (var image = Image.Load(inputPath) as RasterImage)
{
    image.Save(inputPath + ".gif", new GifOptions() { HasTransparentColor = true, BackgroundColor = Color.Transparent, });
}

As concerns case #1, we are going to explore on this topic.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): IMAGINGNET-6760

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

Hello
So the key is BackgroundColor = Color.Transparent
Please use this:
.BackgroundColor = Aspose.Imaging.Color.White
On this image to see what happens:
v.zip (244.8 KB)

I mean if we want to have the White as back color of transparent images?

@australian.dev.nerds , the output of image and export options above is normal, GIF does not support Alpha (transparency) as a feature but has an option to show a single color as transparent.
If you specify BackgroundColor without setting HasTransparentColor, its value is ignored and semi-transparent colors are changed to the closest ones or alpha-trimmed.

1 Like

OK thanks, just one more thing:

Because I convert from various formats to other formats in all combinations, should I use the above dithering in all of format conversions?

Generally you recommend to enable Dithering for transparent images or when converting to Grayscale images or for all images?

I’m confused if FloydSteinbergDithering can be used for all images, transparent, non-transparent, color, grayscale etc?

And about int bitsCount it seems that 1 and 4 and 8 supported? All can be used for all images? For color transparent or color non transparent photos what’s recommended?
Thanks :slight_smile:

@australian.dev.nerds , dithering helps to keep details when trimming image bits-per-pixel, so it is useful in cases when you trim original image bits-per-pixel. Dithering can be used for all raster with no difference whether it has alpha or no. Dithering is especially useful before converting to 1-bit BW.

1 Like

Ok so I found that for GIF I have to:
.HasTransparentColor = True
.BackgroundColor = Aspose.Imaging.Color.Transparent

But for PNG and TIFF, beside PNG Truecolor/Grayscale…WithAlpha and TiffDeflateRgba is similar BGColor thing needed to set, like:
.BackgroundColor = Aspose.Imaging.Color.Transparent ?

@australian.dev.nerds , note that behavior of GIF and PNG/TIFF is different (GIF is indexed color), but still BackgroundColor property is used to set up a background color of an image. I would recommend you to test these options for different image samples and formats!

1 Like

Thank you for your kind support, really appreciated.

Hello, just a follow-up :slight_smile:

@australian.dev.nerds due our free support requests fix planned not earlier than end q2-q3.