public static void Run() { // ExStart:SupportForJPEGBITS // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); int bpp = 2; // Set 2 bits per sample to see the difference in size and quality // The origin PNG with 8 bits per sample string originPngFileName = System.IO.Path.Combine(dataDir, "lena_16g_lin.png"); // The output JPEG-LS with 2 bits per sample. string outputJpegFileName = "lena24b " + bpp + "-bit Gold.jls"; using (PngImage pngImage = (PngImage)Image.Load(originPngFileName)) { JpegOptions jpegOptions = new JpegOptions(); jpegOptions.BitsPerChannel = (byte)bpp; jpegOptions.CompressionType = JpegCompressionMode.JpegLs; pngImage.Save(outputJpegFileName, jpegOptions); } // The output PNG is produced from JPEG-LS to check image visually. string outputPngFileName = "lena24b " + bpp + "-bit Gold.png"; using (JpegImage jpegImage = (JpegImage)Image.Load(outputJpegFileName)) { jpegImage.Save(outputPngFileName, new PngOptions()); } }
public static void Run() { //ExStart:ChangeBackgroundColor // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and cast it into PsdImage using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) { // Convert to PngImage based on PsdImage. using (PngImage pngImage = new PngImage(psdImage)) { int[] pixels = pngImage.LoadArgb32Pixels(pngImage.Bounds); // Iterate through the pixel array and Check the pixel information //that if it is a transparent color pixel and Change the pixel color to white int transparent = pngImage.TransparentColor.ToArgb(); int replacementColor = Color.Yellow.ToArgb(); for (int i = 0; i < pixels.Length; i++) { if (pixels[i] == transparent) { pixels[i] = replacementColor; } } // Replace the pixel array into the image. pngImage.SaveArgb32Pixels(pngImage.Bounds, pixels); pngImage.Save(dataDir + "ChangeBackground_out.png"); } } //ExEnd:ChangeBackgroundColor }
public static void Run() { // ExStart:SpecifyTransparency // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Initialize variables to hold width & height values int width = 0; int height = 0; // Initialize an array of type Color to hold the pixel data Color[] pixels = null; // Create an instance of RasterImage and load a BMP image using (RasterImage raster = (RasterImage)Image.Load(dataDir + "aspose_logo.png")) { // Store the width & height in variables for later use width = raster.Width; height = raster.Height; // Load the pixels of RasterImage into the array of type Color pixels = raster.LoadPixels(new Rectangle(0, 0, width, height)); } // Create & initialize an instance of PngImage while specifying size and PngColorType using (PngImage png = new PngImage(width, height, PngColorType.TruecolorWithAlpha)) { // Save the previously loaded pixels on to the new PngImage and Set TransparentColor property to specify which color to be rendered as transparent png.SavePixels(new Rectangle(0, 0, width, height), pixels); png.TransparentColor = Color.Black; png.HasTransparentColor = true; png.Save(dataDir + "SpecifyTransparencyforPNGImages_out.jpg"); } // ExEnd:SpecifyTransparency }
public static void Run() { //ExStart:PNGtoPDF string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (PngImage image = (PngImage)Image.Load(dataDir + "test.png")) { Aspose.Imaging.ImageOptions.PdfOptions exportOptions = new Aspose.Imaging.ImageOptions.PdfOptions(); exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo(); image.Save(dataDir + "test.pdf", exportOptions); } //ExEnd:PNGtoPDF }
public static void Run() { //ExStart:ChangeWindowSize string dataDir = RunExamples.GetDataDir_PNG(); string sourceFile = @"test.png"; string outputFile = "result.png"; using (PngImage image = (PngImage)Image.Load(dataDir + sourceFile)) { image.BinarizeBradley(10, 20); image.Save(dataDir + outputFile); } //ExEnd:ChangeWindowSize }
public static void Run() { Console.WriteLine("Running example PNGtoPDF"); string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (PngImage image = (PngImage)Image.Load(dataDir + "sample.png")) { Aspose.Imaging.ImageOptions.PdfOptions exportOptions = new Aspose.Imaging.ImageOptions.PdfOptions(); exportOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo(); image.Save(dataDir + "test.pdf", exportOptions); } Console.WriteLine("Finished example PNGtoPDF"); }
public static void Run() { // ExStart:ApplyFilterMethod // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); using (PngImage png = (PngImage)Image.Load(dataDir + "aspose_logo.png")) { // Create an instance of PngOptions, Set the PNG filter method and Save changes to the disc PngOptions options = new PngOptions(); options.FilterType = PngFilterType.Paeth; png.Save(dataDir + "ApplyFilterMethod_out.jpg", options); } // ExEnd:ApplyFilterMethod }
public static void Run() { // ExStart:SpecifyBitDepth // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Load an existing PNG image using (PngImage png = (PngImage)Image.Load(dataDir + "aspose_logo.png")) { // Create an instance of PngOptions, Set the desired ColorType, BitDepth according to the specified ColorType and save image PngOptions options = new PngOptions(); options.ColorType = PngColorType.Grayscale; options.BitDepth = 1; png.Save(dataDir + "SpecifyBitDepth_out.jpg", options); } // ExEnd:SpecifyBitDepth }
public static void Run() { //ExStart:SpecifyTransparency // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and cast it into PsdImage using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) { // Initialize PNG image with psd image pixel data. using (PngImage pngImage = new PngImage(psdImage)) { // specify the PNG image transparency options and save to file. pngImage.TransparentColor = Color.White; pngImage.HasTransparentColor = true; pngImage.Save(dataDir + "Specify_Transparency_result.png"); } } //ExEnd:SpecifyTransparency }
public static void Run() { Console.WriteLine("Running example SettingResolution"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Initialize variables to hold width & height values int width = 0; int height = 0; // Initialize an array of type Color to hold the pixel data Color[] pixels = null; // Create an instance of RasterImage and load a BMP image using (RasterImage raster = (RasterImage)Image.Load(dataDir + "aspose_logo.png")) { // Store the width & height in variables for later use width = raster.Width; height = raster.Height; // Load the pixels of RasterImage into the array of type Color pixels = raster.LoadPixels(new Rectangle(0, 0, width, height)); } // Create & initialize an instance of PngImage while specifying size and PngColorType using (PngImage png = new PngImage(width, height)) { // Save the previously loaded pixels on to the new PngImage png.SavePixels(new Rectangle(0, 0, width, height), pixels); // Create an instance of PngOptions, Set the horizontal & vertical resolutions and Save the result on disc PngOptions options = new PngOptions(); options.ResolutionSettings = new ResolutionSetting(72, 96); png.Save(dataDir + "SettingResolution_output.png", options); } Console.WriteLine("Finished example SettingResolution"); }
public static void Run() { // ExStart:SettingResolution // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Initialize variables to hold width & height values int width = 0; int height = 0; // Initialize an array of type Color to hold the pixel data Color[] pixels = null; // Create an instance of RasterImage and load a BMP image using (RasterImage raster = (RasterImage)Image.Load(dataDir + "aspose_logo.png")) { // Store the width & height in variables for later use width = raster.Width; height = raster.Height; // Load the pixels of RasterImage into the array of type Color pixels = raster.LoadPixels(new Rectangle(0, 0, width, height)); } // Create & initialize an instance of PngImage while specifying size and PngColorType using (PngImage png = new PngImage(width, height)) { // Save the previously loaded pixels on to the new PngImage png.SavePixels(new Rectangle(0, 0, width, height), pixels); // Create an instance of PngOptions, Set the horizontal & vertical resolutions and Save the result on disc PngOptions options = new PngOptions(); options.ResolutionSettings = new ResolutionSetting(72, 96); png.Save(dataDir + "SettingResolution_output.png", options); } // ExEnd:SettingResolution }