Transparent image save issue

Hello
When I load some transparent image (png etc…) and save to other formats which also support transparency, the result is not transparent.
When I save it as psd, also transparency is lost.
Any tip?
Thanks

@australian.dev.nerds, I tried opening a png file with transparency and saving it in psd format, the transparency was preserved. I have attached my project to this post so you can see it.
If you still lose transparency, try setting the appropriate color scheme in the save options.
If you have any questions, do not hesitate to send me code examples and source files, I will try to help you.
ConsoleApp21.zip (1.5 MB)

1 Like

Hello and thanks for the sample,
Well I use image save options with this condition:

If grayscale = true then
PSD.ColorMode = Aspose.Imaging.FileFormats.Psd.ColorModes.Grayscale
PNG.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale
DCM.ColorType = Aspose.Imaging.FileFormats.Dicom.ColorType.Grayscale16Bit
else
PSD.ColorMode = Aspose.Imaging.FileFormats.Psd.ColorModes.Rgb
PNG.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha
DCM.ColorType = Aspose.Imaging.FileFormats.Dicom.ColorType.Rgb24Bit
End If

So are these correct values to preserve transparency?
Psd.ColorModes.Rgb
PngColorType.TruecolorWithAlpha
Dicom.ColorType.Rgb24Bit

Also, for GIF, TGA, DCM I always use only:
New Aspose.Imaging.ImageOptions.GifOptions
New Aspose.Imaging.ImageOptions.TgaOptions
New Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.TiffNoCompressionRgba)
With no parameters set, what to set to preserve transparency for them? :slight_smile:

Psd, Png - correct.
Dicom - doesn’t support transparency at the moment
Png supported transparency for Grayscale - PngColorType.GrayscaleWithAlpha
Tiff - TiffOptions(TiffExpectedFormat.TiffDeflateRgba)
Gif - GifOptions(){HasTransparentColor = true}
Tga - doesn’t support transparency at the moment

Unfortunately, only with parameters.

1 Like

Thanks, all clear, just one question about Tiff:

I used TiffExpectedFormat.TiffNoCompressionRgba which seems to support alpha

You suggested TiffExpectedFormat.TiffDeflateRgba which also support it.

But what’s the difference and if both support transparency, which one is recommended?

And if want to use compression, which one is better supported by aspose, Deflate or LZW?
Thanks.

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

@australian.dev.nerds, For clarity, I simply suggested another option. Both compression options are equally suitable, however, the best of them can only be determined for a specific file based on the parameters speed and compression ratio. These compressors compress the image without loss.