PngImage Constructor (RasterImage, PngColorType) |
Namespace: Aspose.Imaging.FileFormats.Png
[C#] 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"); } }