PngImageHasAlpha Property
Get a value indicating whether this instance has alpha.

Namespace: Aspose.Imaging.FileFormats.Png
Assembly: Aspose.Imaging (in Aspose.Imaging.dll) Version: 21.04
Syntax
public override bool HasAlpha { get; }

Property Value

Type: Boolean
true if this instance has alpha; otherwise, false.
Examples
The following example shows how to check if a PNG image supports alpha-channel.
[C#]

// Get all supported PNG color types.
System.Array colorTypes = System.Enum.GetValues(typeof(Aspose.Imaging.FileFormats.Png.PngColorType));

foreach (Aspose.Imaging.FileFormats.Png.PngColorType colorType in colorTypes)
{
    Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
    createOptions.Source = new Sources.StreamSource(new System.IO.MemoryStream());
    createOptions.ColorType = colorType;

    using (Aspose.Imaging.Image image = Image.Create(createOptions, 100, 100))
    {
        Aspose.Imaging.FileFormats.Png.PngImage pngImage = (Aspose.Imaging.FileFormats.Png.PngImage)image;

        if (pngImage.HasAlpha)
        {
            System.Console.WriteLine("A {0} PNG image supports alpha channel", createOptions.ColorType);
        }
        else
        {
            System.Console.WriteLine("A {0} PNG image doesn't support alpha channel", createOptions.ColorType);
        }
    }
}

// The output looks like this:
// A Grayscale PNG image doesn't support alpha channel
// A Truecolor PNG image doesn't support alpha channel
// A IndexedColor PNG image doesn't support alpha channel
// A GrayscaleWithAlpha PNG image supports alpha channel
// A TruecolorWithAlpha PNG image supports alpha channel
See Also