PngImage Constructor (RasterImage, PngColorType)
Initializes a new instance of the PngImage class.

Namespace: Aspose.Imaging.FileFormats.Png
Assembly: Aspose.Imaging (in Aspose.Imaging.dll) Version: 21.04
public PngImage(
	RasterImage rasterImage,
	PngColorType colorType


Type: Aspose.ImagingRasterImage
The raster image.
Type: Aspose.Imaging.FileFormats.PngPngColorType
The color type.
This example shows how to load PNG image from a BMP image with the specified color type.

string dir = "c:\\temp\\";

// Load a grayscale PNG image from a colored BMP image.
// First, create a temporal BMP image that will be a foundation for building a PNG image.
// You can also load BMP image from a file or use an image of any other raster format.
using (Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(100, 100))
    // Fill the entire BMP image in red.
    Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(bmpImage);
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    gr.FillRectangle(brush, bmpImage.Bounds);

    // The colors of the image pixels will be converted to their grayscale counterparts.
    using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(bmpImage, Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale))
        pngImage.Save(dir + "output.grayscale.png");
See Also