public static void Run() { // ExStart:ResizeWMFFile // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an existing WMF image using (Image image = Image.Load(dataDir + "input.wmf")) { // Call the resize method of Image class and width,height values and Calculate new PNG image height image.Resize(100, 100); double k = (image.Width * 1.00) / image.Height; // Create an instance of EmfRasterizationOptions class and set different properties EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions { BackgroundColor = Color.WhiteSmoke, PageWidth = 100, PageHeight = (int)Math.Round(100 / k), BorderX = 5, BorderY = 10 }; // Create an instance of PngOptions class and provide rasterization option ImageOptionsBase imageOptions = new PngOptions(); imageOptions.VectorRasterizationOptions = emfRasterization; // Call the save method, provide output path and PngOptions to convert the WMF file to PNG and save the output image.Save(dataDir + "CreateEMFMetaFileImage_out.png", imageOptions); // ExStart:ResizeWMFFile } }
public static void Run() { // ExStart:SpecifyFontFolder // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // Create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // Create an instance of PNG options PngOptions pngOptions = new PngOptions(); pngOptions.VectorRasterizationOptions = emfRasterizationOptions; // Load an existing EMF image using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { image.CacheData(); // Set height and width, Reset font settings pngOptions.VectorRasterizationOptions.PageWidth = 300; pngOptions.VectorRasterizationOptions.PageHeight = 350; FontSettings.Reset(); image.Save(dataDir + "Picture1_default_fonts_out.png", pngOptions); // Initialize font list List<string> fonts = new List<string>(FontSettings.GetDefaultFontsFolders()); // Add new font path to font list and Assign list of font folders to font settings and Save the EMF file to PNG image with new font fonts.Add(dataDir + "arialAndTimesAndCourierRegular.xml"); FontSettings.SetFontsFolders(fonts.ToArray(), true); image.Save(dataDir + "Picture1_with_my_fonts_out.png", pngOptions); } // ExEnd:SpecifyFontFolder }
public static void Run() { // ExStart:ExportPSDLayerToRasterImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Create an instance of Image class and load PSD file as image. using (Image image = Image.Load(dataDir + "samplePsd.psd")) { // Cast image object to PSD image var psdImage = (PsdImage)image; // Create an instance of PngOptions class var pngOptions = new PngOptions(); pngOptions.ColorType = PngColorType.TruecolorWithAlpha; // Loop through the list of layers for (int i = 0; i < psdImage.Layers.Length; i++) { // Convert and save the layer to PNG file format. psdImage.Layers[i].Save(string.Format("layer_out{0}.png", i + 1), pngOptions); } } // ExEnd:ExportPSDLayerToRasterImage }
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:ApplyingMotionWienerFilter // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load the image using (SvgImage image = (SvgImage)Image.Load(dataDir + "aspose_logo.Svg")) { // Create an instance of PNG options and Save the results to disk PngOptions pngOptions = new PngOptions(); image.Save(dataDir + "ConvertingSVGToRasterImages_out.png", pngOptions); } // ExEnd:ApplyingMotionWienerFilter }
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:SpecifyBitDepth // 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")) { // 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; psdImage.Save(dataDir + "SpecifyBitDepth_out.png", options); } //ExEnd:SpecifyBitDepth }
public static void Run() { // ExStart:GrayScaleSupportForAlpha // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD in an instance of PsdImage using (Image image = Image.Load(filePath)) { // Cast image object to PSD image PsdImage psdImage = (PsdImage)image; // Create an instance of PngOptions class PngOptions pngOptions = new PngOptions(); pngOptions.ColorType = PngColorType.TruecolorWithAlpha; image.Save("result.png", pngOptions); } // ExEnd:GrayScaleSupportForAlpha }
public static void Run() { // ExStart:ExportPsdLayersToImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an existing image using (Image image = Image.Load(dataDir + "samplePsd.psd")) { var psdImage = (PsdImage)image; var pngOptions = new PngOptions(); pngOptions.ColorType = PngColorType.TruecolorWithAlpha; for (int i = 0; i < psdImage.Layers.Length; i++) { psdImage.Layers[i].Save(dataDir + "layer-" + i + "_out.png", pngOptions); } } // ExEnd:ExportPsdLayersToImages }
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 PngOptions options = new PngOptions(); // Set the PNG filter method options.FilterType = PngFilterType.Paeth; // Save changes to the disc png.Save(dataDir + "ApplyFilterMethod_out.jpg", options); } // ExEnd:ApplyFilterMethod }
public static void Run() { // ExStart:ExportPsdLayersToImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an existing image using (Image image = Image.Load(dataDir + "samplePsd.psd")) { var psdImage = (PsdImage)image; var pngOptions = new PngOptions(); pngOptions.ColorType = PngColorType.TruecolorWithAlpha; for (int i = 0; i < psdImage.Layers.Length; i++) { psdImage.Layers[i].Save(dataDir + "layer-" + i +"_out.png", pngOptions); } } // ExEnd:ExportPsdLayersToImages }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:PSDToRasterImageFormats String srcPath = dataDir + @"sample.psd"; string destName = dataDir + @"export"; // Load an existing PSD image as Image using (Image image = Image.Load(srcPath)) { // Create an instance of PngOptions class PngOptions pngOptions = new PngOptions(); // Create an instance of BmpOptions class BmpOptions bmpOptions = new BmpOptions(); // Create an instance of TiffOptions class TiffOptions tiffOptions = new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.Default); // Create an instance of GifOptions class GifOptions gifOptions = new GifOptions(); // Create an instance of JpegOptions class JpegOptions jpegOptions = new JpegOptions(); // Create an instance of Jpeg2000Options class Jpeg2000Options jpeg2000Options = new Jpeg2000Options(); // Call the save method, provide output path and export options to convert PSD file to various raster file formats. image.Save(destName + ".png", pngOptions); image.Save(destName + ".bmp", bmpOptions); image.Save(destName + ".tiff", tiffOptions); image.Save(destName + ".gif", gifOptions); image.Save(destName + ".jpeg", jpegOptions); image.Save(destName + ".jp2", jpeg2000Options); } //ExEnd:PSDToRasterImageFormats }
public static void Run() { // ExStart:SpecifyFontFolder // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // create an instance of PNG options PngOptions pngOptions = new PngOptions(); pngOptions.VectorRasterizationOptions = emfRasterizationOptions; // load an existing EMF image using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { image.CacheData(); // set heigh and width pngOptions.VectorRasterizationOptions.PageWidth = 300; pngOptions.VectorRasterizationOptions.PageHeight = 350; // reset font settings FontSettings.Reset(); image.Save(dataDir + "Picture1_default_fonts_out.png", pngOptions); // initialize font list List <string> fonts = new List <string>(FontSettings.GetDefaultFontsFolders()); // add new font path to font list fonts.Add(dataDir + "arialAndTimesAndCourierRegular.xml"); // assign list of font folders to font settings FontSettings.SetFontsFolders(fonts.ToArray(), true); // save the EMF file to PNG image with new font image.Save(dataDir + "Picture1_with_my_fonts_out.png", pngOptions); } }
public static void Run() { // ExStart:CompressingFiles // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Load an image from file (or stream) using (Image image = Image.Load(dataDir + "aspose_logo.png")) { // Loop over possible CompressionLevel range for (int i = 0; i <= 9; i++) { // Create an instance of PngOptions for each resultant PNG, Set CompressionLevel and Save result on disk PngOptions options = new PngOptions(); options.CompressionLevel = i; image.Save(i + "_out.png", options); } } // ExEnd:CompressingFiles }
public static void Run() { //ExStart:SupportOfClippingMask // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Exposure layer editing // Export of the psd with complex clipping mask string sourceFileName = dataDir + "ClippingMaskComplex.psd"; string exportPath = dataDir + "ClippingMaskComplex.png"; using (var im = (PsdImage)Image.Load(sourceFileName)) { // Export to PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(exportPath, saveOptions); } //ExEnd:SupportOfClippingMask }
public static void ExportToPNG() { // ExStart: ExportingSTLtoPNG string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string sourceFilePath = MyDir + "galeon.stl"; using (var cadImage = (CadImage)Image.Load(sourceFilePath)) { var rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.CenterDrawing = true; rasterizationOptions.PageWidth = 100; rasterizationOptions.PageHeight = 100; PngOptions pngOptions = new PngOptions(); pngOptions.VectorRasterizationOptions = rasterizationOptions; string outPath = sourceFilePath + ".png"; cadImage.Save(outPath, pngOptions); } }
public static void Run() { //ExStart:CompressingFiles // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PNG(); // Load an image from file (or stream) using (Image image = Image.Load(dataDir + "aspose_logo.png")) { // Loop over possible CompressionLevel range for (int i = 0; i <= 9; i++) { // Create an instance of PngOptions for each resultant PNG, Set CompressionLevel and Save result on disk PngOptions options = new PngOptions(); options.CompressionLevel = i; image.Save(i + "_out.png", options); } } //ExEnd:CompressingFiles }
public override void GeneratePreview(Stream docStream, IPreviewGenerationContext context) { docStream.Seek(0, SeekOrigin.Begin); var document = (TiffImage)Image.Load(docStream); if (context.StartIndex == 0) { context.SetPageCount(document.Frames.Length); } int firstIndex; int lastIndex; var loggedPageError = false; context.SetIndexes(document.Frames.Length, out firstIndex, out lastIndex); for (var i = firstIndex; i <= lastIndex; i++) { try { document.ActiveFrame = document.Frames[i]; using (var imgStream = new MemoryStream()) { var options = new PngOptions(); document.Save(imgStream, options); context.SavePreviewAndThumbnail(imgStream, i + 1); } } catch (Exception ex) { if (Tools.HandlePageError(ex, i + 1, context, !loggedPageError)) { return; } loggedPageError = true; } } }
public static void Run() { //ExStart:CompressingFiles // 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")) { // Loop over possible CompressionLevel range for (int i = 0; i <= 9; i++) { // Create an instance of PngOptions for each resultant PNG, Set CompressionLevel and Save result on disk PngOptions options = new PngOptions(); options.CompressionLevel = i; psdImage.Save(dataDir + i + "_out.png", options); } } //ExEnd:CompressingFiles }
///<Summary> /// ConvertCadToImages method to convert cad to images ///</Summary> public Response ConvertCadToImages(string fileName, string folderName, string outputType) { if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") || outputType.Equals("gif") || outputType.Equals("svg")) { ImageOptionsBase imageOptionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { imageOptionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { imageOptionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { imageOptionsBase = new GifOptions(); } else if (outputType.Equals("svg")) { imageOptionsBase = new SvgOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, false, false, delegate(string inFilePath, string outPath, string zipOutFolder) { using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(inFilePath)) { image.Save(outPath, imageOptionsBase); } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // ExStart:ExportPsdLayersToImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an existing image using (Image image = Image.Load(dataDir + "samplePsd.psd")) { var psdImage = (PsdImage)image; var pngOptions = new PngOptions(); pngOptions.ColorType = PngColorType.TruecolorWithAlpha; for (int i = 0; i < psdImage.Layers.Length; i++) { psdImage.Layers[i].Save(dataDir + "layer-" + i + "_out.png", pngOptions); } } // ExEnd:ExportPsdLayersToImages }
public static void Run() { string dataDir = RunExamples.GetDataDir_PNG(); //ExStart:SupportForInterruptMonitor ImageOptionsBase saveOptions = new PngOptions(); InterruptMonitor monitor = new InterruptMonitor(); string source = Path.Combine(dataDir, "big2.psb"); string output = Path.Combine(dataDir, "big_out.png"); SaveImageWorker worker = new SaveImageWorker(source, output, saveOptions, monitor); Thread thread = new Thread(new ThreadStart(worker.ThreadProc)); try { thread.Start(); // The timeout should be less than the time required for full image conversion (without interruption). Thread.Sleep(3000); // Interrupt the process monitor.Interrupt(); Console.WriteLine("Interrupting the save thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now); // Wait for interruption... thread.Join(); } finally { // Delete the output file. if (File.Exists(output)) { File.Delete(output); } } //ExEnd:SupportForInterruptMonitor }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:FontReplacement // The path to the documents directory. // Load an image in an instance of image and setting default replacement font. PsdLoadOptions psdLoadOptions = new PsdLoadOptions() { DefaultReplacementFont = "Arial" }; using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "Cloud_AzPlat_Banner3A_SB_EN_US_160x600_chinese_font.psd", psdLoadOptions)) { var pngOptions = new PngOptions(); psdImage.Save(dataDir + "replaced_font.png", new ImageOptions.PngOptions()); } //ExEnd:FontReplacement }
public static void ExportToPNG() { //ExStart:ExportingIFCtoPNG //Setfile name path as other examples string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string sourceFilePath = MyDir + "example.ifc"; using (IfcImage cadImage = (IfcImage)Image.Load(sourceFilePath)) { CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); // rasterizationOptions.CenterDrawing = true; rasterizationOptions.PageWidth = 100; rasterizationOptions.PageHeight = 100; PngOptions pngOptions = new PngOptions(); pngOptions.VectorRasterizationOptions = rasterizationOptions; //Set output path as well string outPath = sourceFilePath + ".png"; cadImage.Save(outPath, pngOptions); } }
///<Summary> /// ConvertPSDToImageFiles method to convert psd to image ///</Summary> public Response ConvertPSDToImageFiles(string fileName, string folderName, string outputType) { if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png")) { ImageOptionsBase optionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { optionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { optionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { optionsBase = new GifOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, true, false, delegate(string inFilePath, string outPath, string zipOutFolder) { string fileExtension = Path.GetExtension(inFilePath).ToLower(); using (Image image = Image.Load(inFilePath)) { image.Save(outPath, optionsBase); } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }
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() { // The path to the documents directory. string SourceDir = RunExamples.GetDataDir_PSD(); string OutputDir = RunExamples.GetDataDir_Output(); //ExStart:1 string sourceFile = SourceDir + @"text_ethalon_different_colors.psd"; string destName = OutputDir + @"RenderTextWithDifferentColorsInTextLayer_out.png"; // Load the noisy image using (var psdImage = (PsdImage)Image.Load(sourceFile)) { var txtLayer = (TextLayer)psdImage.Layers[1]; txtLayer.TextData.UpdateLayerData(); PngOptions pngOptions = new PngOptions(); pngOptions.ColorType = PngColorType.TruecolorWithAlpha; psdImage.Save(destName, pngOptions); } //ExEnd:1 Console.WriteLine("RenderTextWithDifferentColorsInTextLayer executed successfully"); }
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 PngOptions options = new PngOptions(); // Set the desired ColorType options.ColorType = PngColorType.Grayscale; // Set the BitDepth according to the specified ColorType options.BitDepth = 1; // Save changes to the disc png.Save(dataDir + "SpecifyBitDepth_out.jpg", options); } // ExEnd:SpecifyBitDepth }
public static void Run() { // ExStart:ConvertSpecificPortionOfDjVuPage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DjVu(); // Load a DjVu image using (DjvuImage image = (DjvuImage)Image.Load(dataDir + "Sample.djvu")) { // Create an instance of PngOptions and Set ColorType to Grayscale PngOptions exportOptions = new PngOptions(); exportOptions.ColorType = PngColorType.Grayscale; // Create an instance of Rectangle and specify the portion on DjVu page Rectangle exportArea = new Rectangle(0, 0, 500, 500); // Specify the DjVu page index and Initialize an instance of DjvuMultiPageOptions while passing index of DjVu page index and instance of Rectangle covering the area to be exported int exportPageIndex = 2; exportOptions.MultiPageOptions = new DjvuMultiPageOptions(exportPageIndex, exportArea); image.Save(dataDir + "ConvertSpecificPortionOfDjVuPage_out.djvu", exportOptions); } // ExEnd:ConvertSpecificPortionOfDjVuPage }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:RenderingOfLevelAdjustmentLayer string sourceFileName = dataDir + "LevelsAdjustmentLayer.psd"; string psdPathAfterChange = dataDir + "LevelsAdjustmentLayerChanged.psd"; string pngExportPath = dataDir + "LevelsAdjustmentLayerChanged.png"; using (var im = (PsdImage)Image.Load(sourceFileName)) { foreach (var layer in im.Layers) { if (layer is LevelsLayer) { var levelsLayer = (LevelsLayer)layer; var channel = levelsLayer.GetChannel(0); channel.InputMidtoneLevel = 2.0f; channel.InputShadowLevel = 10; channel.InputHighlightLevel = 230; channel.OutputShadowLevel = 20; channel.OutputHighlightLevel = 200; } } // Save PSD im.Save(psdPathAfterChange); // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } //ExEnd:RenderingOfLevelAdjustmentLayer }
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 }
public static void Run() { //ExStart:ExportPSDLayerToRasterImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and caste it into PsdImage using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "sample.psd")) { // Create an instance of PngOptions class var pngOptions = new PngOptions(); pngOptions.ColorType = PngColorType.TruecolorWithAlpha; // Loop through the list of layers for (int i = 0; i < psdImage.Layers.Length; i++) { // Convert and save the layer to PNG file format. psdImage.Layers[i].Save(string.Format("layer_out{0}.png", i + 1), pngOptions); } } //ExEnd:ExportPSDLayerToRasterImage }
public static void Run() { //ExStart:RenderingExportOfChannelMixerAdjusmentLyer // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Rgb Channel Mixer string sourceFileName = dataDir + "ChannelMixerAdjustmentLayerRgb.psd"; string psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerRgbChanged.psd"; string pngExportPath = dataDir + "ChannelMixerAdjustmentLayerRgbChanged.png"; using (var im = (PsdImage)Image.Load(sourceFileName)) { foreach (var layer in im.Layers) { if (layer is RgbChannelMixerLayer) { var rgbLayer = (RgbChannelMixerLayer)layer; rgbLayer.RedChannel.Blue = 100; rgbLayer.BlueChannel.Green = -100; rgbLayer.GreenChannel.Constant = 50; } } // Save PSD im.Save(psdPathAfterChange); // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } // Cmyk Channel Mixer sourceFileName = dataDir + "ChannelMixerAdjustmentLayerCmyk.psd"; psdPathAfterChange = dataDir + "ChannelMixerAdjustmentLayerCmykChanged.psd"; pngExportPath = dataDir + "ChannelMixerAdjustmentLayerCmykChanged.png"; using (var im = (PsdImage)Image.Load(sourceFileName)) { foreach (var layer in im.Layers) { if (layer is CmykChannelMixerLayer) { var cmykLayer = (CmykChannelMixerLayer)layer; cmykLayer.CyanChannel.Black = 20; cmykLayer.MagentaChannel.Yellow = 50; cmykLayer.YellowChannel.Cyan = -25; cmykLayer.BlackChannel.Yellow = 25; } } // Save PSD im.Save(psdPathAfterChange); // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } //ExEnd:RenderingExportOfChannelMixerAdjusmentLyer }
///<Summary> /// ConvertImageFormat method to convert image to different image formats ///</Summary> public Response ConvertImageFormat(string fileName, string folderName, string outputType) { if (outputType.Equals("gif") || outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") || outputType.Equals("psd") || outputType.Equals("emf") || outputType.Equals("svg") || outputType.Equals("wmf")) { ImageOptionsBase optionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { optionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { optionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { optionsBase = new GifOptions(); } else if (outputType.Equals("psd")) { optionsBase = new PsdOptions(); } else if (outputType.Equals("emf")) { optionsBase = new EmfOptions(); } else if (outputType.Equals("svg")) { optionsBase = new SvgOptions(); } else if (outputType.Equals("wmf")) { optionsBase = new WmfOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, true, true, delegate(string inFilePath, string outPath, string zipOutFolder) { string fileExtension = Path.GetExtension(inFilePath).ToLower(); if ((fileExtension == ".tif") || (fileExtension == ".tiff")) { string outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}"; using (TiffImage multiImage = (TiffImage)Image.Load(inFilePath)) { if (multiImage.Frames.Length > 1) { int frameCounter = 0; // Iterate over the TiffFrames in TiffImage foreach (TiffFrame tiffFrame in multiImage.Frames) { multiImage.ActiveFrame = tiffFrame; // Load Pixels of TiffFrame into an array of Colors Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds); // Create an instance of JpegOptions // Set the Source of JpegOptions as FileCreateSource by specifying the location where output will be saved // Last boolean parameter denotes isTemporal outPath = zipOutFolder + "/" + outfileName; optionsBase.Source = new FileCreateSource(string.Format(outPath, frameCounter + 1) + "." + outputType, false); // Create a new RasterImage of Jpeg type using (var jpgImage = (RasterImage)Image.Create(optionsBase, tiffFrame.Width, tiffFrame.Height)) { // Save the JpegImage with pixels from TiffFrame jpgImage.SavePixels(tiffFrame.Bounds, pixels); // Resize the Jpeg Image jpgImage.Resize(100, 100, ResizeType.NearestNeighbourResample); // Save the results on disk jpgImage.Save(); } frameCounter++; } } else { multiImage.Save(outPath, optionsBase); } } } else { using (Image image = Image.Load(inFilePath)) { image.Save(outPath, optionsBase); } } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }