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: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
        }
Пример #3
0
        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
        }