public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:DrawingLines // Create an instance of BmpOptions and set its various properties string outpath = dataDir + "Lines.bmp"; BmpOptions saveOptions = new BmpOptions(); saveOptions.BitsPerPixel = 32; // Create an instance of Image using (Image image = new PsdImage(100, 100)) { // Create and initialize an instance of Graphics class and Clear Graphics surface Graphics graphic = new Graphics(image); graphic.Clear(Color.Yellow); // Draw two dotted diagonal lines by specifying the Pen object having blue color and co-ordinate Points graphic.DrawLine(new Pen(Color.Blue), 9, 9, 90, 90); graphic.DrawLine(new Pen(Color.Blue), 9, 90, 90, 9); // Draw a four continuous line by specifying the Pen object having Solid Brush with red color and two point structures graphic.DrawLine(new Pen(new SolidBrush(Color.Red)), new Point(9, 9), new Point(9, 90)); graphic.DrawLine(new Pen(new SolidBrush(Color.Aqua)), new Point(9, 90), new Point(90, 90)); graphic.DrawLine(new Pen(new SolidBrush(Color.Black)), new Point(90, 90), new Point(90, 9)); graphic.DrawLine(new Pen(new SolidBrush(Color.White)), new Point(90, 9), new Point(9, 9)); image.Save(outpath, saveOptions); } //ExEnd:DrawingLines }
public static void Run() { //ExStart:ReadSpecificEXIFTagsInformation // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "1280px-Zebras_Serengeti.psd")) { // Iterate over resources. foreach (var resource in image.ImageResources) { // Find thumbnail resource. Typically they are in the Jpeg file format. if (resource is ThumbnailResource || resource is Thumbnail4Resource) { // Extract exif data and print to the console. var exif = ((ThumbnailResource)resource).JpegOptions.ExifData; if (exif != null) { Console.WriteLine("Exif WhiteBalance: " + exif.WhiteBalance); Console.WriteLine("Exif PixelXDimension: " + exif.PixelXDimension); Console.WriteLine("Exif PixelYDimension: " + exif.PixelYDimension); Console.WriteLine("Exif ISOSpeed: " + exif.ISOSpeed); Console.WriteLine("Exif FocalLength: " + exif.FocalLength); } } } } //ExEnd:ReadSpecificEXIFTagsInformation }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:DrawingEllipse // Create an instance of BmpOptions and set its various properties string outpath = dataDir + "Ellipse.bmp"; // Create an instance of BmpOptions and set its various properties BmpOptions saveOptions = new BmpOptions(); saveOptions.BitsPerPixel = 32; // Create an instance of Image using (Image image = new PsdImage(100, 100)) { // Create and initialize an instance of Graphics class and Clear Graphics surface Graphics graphic = new Graphics(image); graphic.Clear(Color.Yellow); // Draw a dotted ellipse shape by specifying the Pen object having red color and a surrounding Rectangle graphic.DrawEllipse(new Pen(Color.Red), new Rectangle(30, 10, 40, 80)); // Draw a continuous ellipse shape by specifying the Pen object having solid brush with blue color and a surrounding Rectangle graphic.DrawEllipse(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40)); // export image to bmp file format. image.Save(outpath, saveOptions); } //ExEnd:DrawingEllipse }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:CoreDrawingFeatures // Create an instance of BmpOptions and set its various properties string loadpath = dataDir + "sample.psd"; string outpath = dataDir + "CoreDrawingFeatures.bmp"; // Create an instance of Image using (PsdImage image = new PsdImage(loadpath)) { // load pixels var pixels = image.LoadArgb32Pixels(new Rectangle(0, 0, 100, 10)); for (int i = 0; i < pixels.Length; i++) { // specify pixel color value (gradient in this case). pixels[i] = i; } // save modified pixels. image.SaveArgb32Pixels(new Rectangle(0, 0, 100, 10), pixels); // export image to bmp file format. image.Save(outpath, new BmpOptions()); } //ExEnd:CoreDrawingFeatures }
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")) { int[] pixels = psdImage.LoadArgb32Pixels(psdImage.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 = psdImage.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. psdImage.SaveArgb32Pixels(psdImage.Bounds, pixels); psdImage.Save(dataDir + "ChangeBackground_out.png", new PngOptions()); } //ExEnd:ChangeBackgroundColor }
public static void Run() { //ExStart:ImportImageToPSDLayer // 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 image = (PsdImage)Image.Load(dataDir + "sample.psd")) { //Extract a layer from PSDImage Layer layer = image.Layers[1]; // Create an image that is needed to be imported into the PSD file. using (PngImage drawImage = new PngImage(200, 200)) { // Fill image surface as needed. Graphics g = new Graphics(drawImage); g.Clear(Color.Yellow); // Call DrawImage method of the Layer class and pass the image instance. layer.DrawImage(new Point(10, 10), drawImage); } // Save the results to output path. image.Save(dataDir + "ImportImageToPSDLayer_out.psd"); } //ExEnd:ImportImageToPSDLayer }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:SupportFor2_7BitsJPEG // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) { JpegOptions options = new JpegOptions(); // Set 2 bits per sample to see the difference in size and quality byte bpp = 2; //Just replace one line given below in examples to use YCCK instead of CMYK //options.ColorType = JpegCompressionColorMode.Cmyk; options.ColorType = JpegCompressionColorMode.Cmyk; options.CompressionType = JpegCompressionMode.JpegLs; options.BitsPerChannel = bpp; // The default profiles will be used. options.RgbColorProfile = null; options.CmykColorProfile = null; image.Save(dataDir + "2_7BitsJPEG_output.jpg", options); } //ExEnd:SupportFor2_7BitsJPEG }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:ReadAllEXIFTagList // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "1280px-Zebras_Serengeti.psd")) { // Iterate over resources. foreach (var resource in image.ImageResources) { // Find thumbnail resource. Typically they are in the Jpeg file format. if (resource is ThumbnailResource || resource is Thumbnail4Resource) { // Extract thumbnail data and store it as a separate image file. var thumbnail = (ThumbnailResource)resource; var exifData = thumbnail.JpegOptions.ExifData; if (exifData != null) { Type type = exifData.GetType(); PropertyInfo[] properties = type.GetProperties(); foreach (PropertyInfo property in properties) { Console.WriteLine(property.Name + ":" + property.GetValue(exifData, null)); } } } } } //ExEnd:ReadAllEXIFTagList }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:ExtractThumbnailFromJFIF // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "1280px-Zebras_Serengeti.psd")) { // Iterate over resources. foreach (var resource in image.ImageResources) { // Find thumbnail resource. Typically they are in the Jpeg file format. if (resource is ThumbnailResource || resource is Thumbnail4Resource) { // Extract thumbnail data and store it as a separate image file. var thumbnail = (ThumbnailResource)resource; var jfif = thumbnail.JpegOptions.Jfif; if (jfif != null) { // extract JFIF data and process. } var exif = thumbnail.JpegOptions.ExifData; if (exif != null) { // extract Exif data and process. } } } } //ExEnd:ExtractThumbnailFromJFIF }
public static void Run() { string baseFolder = RunExamples.GetDataDir_PSD(); //ExStart:SupportOfObArAndUnFlSignatures //ExSummary:The following code demonstrates the support of the ObAr and UnFl signatures. void AssertAreEqual(object actual, object expected) { if (!object.Equals(actual, expected)) { throw new FormatException(string.Format("Actual value {0} are not equal to expected {1}.", actual, expected)); } } var sourceFilePath = baseFolder + "LayeredSmartObjects8bit2.psd"; using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) { UnitArrayStructure verticalStructure = null; foreach (Layer imageLayer in image.Layers) { foreach (var imageResource in imageLayer.Resources) { var resource = imageResource as PlLdResource; if (resource != null && resource.IsCustom) { foreach (OSTypeStructure structure in resource.Items) { if (structure.KeyName.ClassName == "customEnvelopeWarp") { AssertAreEqual(typeof(DescriptorStructure), structure.GetType()); var custom = (DescriptorStructure)structure; AssertAreEqual(custom.Structures.Length, 1); var mesh = custom.Structures[0]; AssertAreEqual(typeof(ObjectArrayStructure), mesh.GetType()); var meshObjectArray = (ObjectArrayStructure)mesh; AssertAreEqual(meshObjectArray.Structures.Length, 2); var vertical = meshObjectArray.Structures[1]; AssertAreEqual(typeof(UnitArrayStructure), vertical.GetType()); verticalStructure = (UnitArrayStructure)vertical; AssertAreEqual(verticalStructure.UnitType, UnitTypes.Pixels); AssertAreEqual(verticalStructure.ValueCount, 16); break; } } } } } AssertAreEqual(true, verticalStructure != null); } //ExEnd:SupportOfObArAndUnFlSignatures Console.WriteLine("SupportOfObArAndUnFlSignatures executed successfully"); }
public static void Run() { //ExStart:SupportOfConvertingLayerToSmartObject // Tests that the layer, imported from an image, is converted to smart object layer and the saved PSD file is correct. // The path to the documents directory. string SourceDir = RunExamples.GetDataDir_PSD(); string OutputDir = RunExamples.GetDataDir_Output(); string outputFilePath = OutputDir + "layerTest2.psd"; string outputPngFilePath = Path.ChangeExtension(outputFilePath, ".png"); using (PsdImage image = (PsdImage)Image.Load(SourceDir + "layerTest1.psd")) { string layerFilePath = SourceDir + "picture.jpg"; using (var stream = new FileStream(layerFilePath, FileMode.Open)) { Layer layer = null; try { layer = new Layer(stream); image.AddLayer(layer); } catch (Exception) { if (layer != null) { layer.Dispose(); } throw; } var layer2 = image.Layers[2]; var layer3 = image.SmartObjectProvider.ConvertToSmartObject(image.Layers.Length - 1); var bounds = layer3.Bounds; layer3.Left = (image.Width - layer3.Width) / 2; layer3.Top = layer2.Top; layer3.Right = layer3.Left + bounds.Width; layer3.Bottom = layer3.Top + bounds.Height; image.Save(outputFilePath); image.Save(outputPngFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } //ExEnd:SupportOfConvertingLayerToSmartObject File.Delete(outputFilePath); File.Delete(outputPngFilePath); Console.WriteLine("SupportOfConvertingLayerToSmartObject executed successfully"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:RenderingExposureAdjustmentLayer // Exposure layer editing string sourceFileName = dataDir + "ExposureAdjustmentLayer.psd"; string psdPathAfterChange = dataDir + "ExposureAdjustmentLayerChanged.psd"; string pngExportPath = dataDir + "ExposureAdjustmentLayerChanged.png"; using (var im = (PsdImage)Image.Load(sourceFileName)) { foreach (var layer in im.Layers) { if (layer is ExposureLayer) { var expLayer = (ExposureLayer)layer; expLayer.Exposure = 2; expLayer.Offset = -0.25f; expLayer.GammaCorrection = 0.5f; } } // Save PSD im.Save(psdPathAfterChange); // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } // Exposure layer adding sourceFileName = dataDir + "PhotoExample.psd"; psdPathAfterChange = dataDir + "PhotoExampleAddedExposure.psd"; pngExportPath = dataDir + "PhotoExampleAddedExposure.png"; using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) { var newlayer = im.AddExposureAdjustmentLayer(); newlayer.Exposure = 2; newlayer.Offset = -0.25f; newlayer.GammaCorrection = 2f; // Save PSD im.Save(psdPathAfterChange); // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } //ExEnd:RenderingExposureAdjustmentLayer }
public static void Run() { //ExStart:SupportOfSectionDividerLayer // The following code demonstrates SectionDividerLayer layers and how to get the related to it LayerGroup. // Layers hierarchy // [0]: '</Layer group>' SectionDividerLayer for Group 1 // [1]: 'Layer 1' Regular Layer // [2]: '</Layer group>' SectionDividerLayer for Group 2 // [3]: '</Layer group>' SectionDividerLayer for Group 3 // [4]: 'Group 3' GroupLayer // [5]: 'Group 2' GroupLayer // [6]: 'Group 1' GroupLayer void AssertAreEqual(object expected, object actual, string message = null) { if (!object.Equals(expected, actual)) { throw new Exception(message ?? "Objects are not equal."); } } using (var image = new PsdImage(100, 100)) { // Creating layers hierarchy // Add the LayerGroup 'Group 1' LayerGroup group1 = image.AddLayerGroup("Group 1", 0, true); // Add regular layer Layer layer1 = new Layer(); layer1.DisplayName = "Layer 1"; group1.AddLayer(layer1); // Add the LayerGroup 'Group 2' LayerGroup group2 = group1.AddLayerGroup("Group 2", 1); // Add the LayerGroup 'Group 3' LayerGroup group3 = group2.AddLayerGroup("Group 3", 0); // Gets the SectionDividerLayer's SectionDividerLayer divider1 = (SectionDividerLayer)image.Layers[0]; SectionDividerLayer divider2 = (SectionDividerLayer)image.Layers[2]; SectionDividerLayer divider3 = (SectionDividerLayer)image.Layers[3]; // using the SectionDividerLayer.GetRelatedLayerGroup() method, obtains the related LayerGroup instance. AssertAreEqual(group1.DisplayName, divider1.GetRelatedLayerGroup().DisplayName); // the same LayerGroup AssertAreEqual(group2.DisplayName, divider2.GetRelatedLayerGroup().DisplayName); // the same LayerGroup AssertAreEqual(group3.DisplayName, divider3.GetRelatedLayerGroup().DisplayName); // the same LayerGroup LayerGroup folder1 = divider1.GetRelatedLayerGroup(); AssertAreEqual(5, folder1.Layers.Length); // 'Group 1' contains 5 layers } //ExEnd:SupportOfSectionDividerLayer Console.WriteLine("SupportOfSectionDividerLayer executed successfully"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddHueSaturationAdjustmentLayer // Hue/Saturation layer editing string sourceFileName = dataDir + "HueSaturationAdjustmentLayer.psd"; string psdPathAfterChange = dataDir + "HueSaturationAdjustmentLayerChanged.psd"; using (var im = (PsdImage)Image.Load(sourceFileName)) { foreach (var layer in im.Layers) { if (layer is HueSaturationLayer) { var hueLayer = (HueSaturationLayer)layer; hueLayer.Hue = -25; hueLayer.Saturation = -12; hueLayer.Lightness = 67; var colorRange = hueLayer.GetRange(2); colorRange.Hue = -40; colorRange.Saturation = 50; colorRange.Lightness = -20; colorRange.MostLeftBorder = 300; } } im.Save(psdPathAfterChange); } // Hue/Saturation layer adding sourceFileName = dataDir + "PhotoExample.psd"; psdPathAfterChange = dataDir + "PhotoExampleAddedHueSaturation.psd"; using (PsdImage im = (PsdImage)Image.Load(sourceFileName)) { //this.SaveForVisualTest(im, this.OutputPath, prefix + file, "before"); var hueLayer = im.AddHueSaturationAdjustmentLayer(); hueLayer.Hue = -25; hueLayer.Saturation = -12; hueLayer.Lightness = 67; var colorRange = hueLayer.GetRange(2); colorRange.Hue = -160; colorRange.Saturation = 100; colorRange.Lightness = 20; colorRange.MostLeftBorder = 300; im.Save(psdPathAfterChange); } //ExEnd:AddHueSaturationAdjustmentLayer }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:UpdateTextLayerInPSDFile //The following example demonstrates how you can obtain the document conversion progress string sourceFilePath = Path.Combine(dataDir, "Apple.psd"); Stream outputStream = new MemoryStream(); ProgressEventHandler localProgressEventHandler = delegate(ProgressEventHandlerInfo progressInfo) { string message = string.Format( "{0} {1}: {2} out of {3}", progressInfo.Description, progressInfo.EventType, progressInfo.Value, progressInfo.MaxValue); Console.WriteLine(message); }; Console.WriteLine("---------- Loading Apple.psd ----------"); var loadOptions = new PsdLoadOptions() { ProgressEventHandler = localProgressEventHandler }; using (PsdImage image = (PsdImage)Image.Load(sourceFilePath, loadOptions)) { Console.WriteLine("---------- Saving Apple.psd to PNG format ----------"); image.Save( outputStream, new PngOptions() { ColorType = PngColorType.Truecolor, ProgressEventHandler = localProgressEventHandler }); Console.WriteLine("---------- Saving Apple.psd to PSD format ----------"); image.Save( outputStream, new PsdOptions() { ColorMode = ColorModes.Rgb, ChannelsCount = 4, ProgressEventHandler = localProgressEventHandler }); } //ExEnd:UpdateTextLayerInPSDFile Console.WriteLine("UsingDocumentConversionProgressHandler example executed successfully"); }
public static void Run() { // The path to the documents directory. string baseDir = RunExamples.GetDataDir_PSD(); string outputDir = RunExamples.GetDataDir_Output(); //ExStart:SupportOfPassThroughBlendingMode //ExSummary:The following example demonstrates how you can use the PassThrough layer blend mode in Aspose.PSD string sourceFileName = baseDir + "Apple.psd"; string outputFileName = outputDir + "OutputApple"; using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) { if (image.Layers.Length < 23) { throw new Exception("There is not 23rd layer."); } var layer = image.Layers[23] as LayerGroup; if (layer == null) { throw new Exception("The 23rd layer is not a layer group."); } if (layer.Name != "AdjustmentGroup") { throw new Exception("The 23rd layer name is not 'AdjustmentGroup'."); } if (layer.BlendModeKey != BlendMode.PassThrough) { throw new Exception("AdjustmentGroup layer should have 'pass through' blend mode."); } image.Save(outputFileName + ".psd", new PsdOptions(image)); image.Save(outputFileName + ".png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); layer.BlendModeKey = BlendMode.Normal; image.Save(outputFileName + "Normal.psd", new PsdOptions(image)); image.Save(outputFileName + "Normal.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } //ExEnd:SupportOfPassThroughBlendingMode Console.WriteLine("SupportOfPassThroughBlendingMode executed successfully"); }
public static void Run() { // The path to the documents directory. string baseFolder = RunExamples.GetDataDir_PSD(); string outputDir = RunExamples.GetDataDir_Output(); //ExStart:SupportOfBritResource /* This Example demonstrates how you can programmatically change the PSD Image Brightness/Contrast Layer Resource - BritResource * This is a Low-Level Aspose.PSD API. You can use Brightness/Contrast Layer through its API, which will be much easier, * but direct PhotoShop resource editing gives you more control over the PSD file content. */ string path = Path.Combine(baseFolder, "BrightnessContrastPS6.psd"); string outputPath = Path.Combine(outputDir, "BrightnessContrastPS6_output.psd"); using (PsdImage im = (PsdImage)Image.Load(path)) { foreach (var layer in im.Layers) { if (layer is BrightnessContrastLayer) { foreach (var layerResource in layer.Resources) { if (layerResource is BritResource) { var resource = (BritResource)layerResource; if (resource.Brightness != -40 || resource.Contrast != 10 || resource.LabColor != false || resource.MeanValueForBrightnessAndContrast != 127) { throw new Exception("BritResource was read wrong"); } // Test editing and saving resource.Brightness = 25; resource.Contrast = -14; resource.LabColor = true; resource.MeanValueForBrightnessAndContrast = 200; im.Save(Path.Combine(outputPath, outputPath), new PsdOptions()); break; } } } } } //ExEnd:SupportOfBritResource Console.WriteLine("SupportOfBritResource executed successfully"); }
public static void Run() { string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:PSDToPDFWithAdjustmentLayers using (PsdImage image = (PsdImage)Image.Load(dataDir + "example.psd")) { image.Save(dataDir + "document.pdf", new PdfOptions()); } //ExEnd:PSDToPDFWithAdjustmentLayers }
public static void Run() { string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:PSDToPDFWithClippingMask using (PsdImage image = (PsdImage)Image.Load(dataDir + "clip.psd")) { image.Save(dataDir + "output.pdf", new PdfOptions()); } //ExEnd:PSDToPDFWithClippingMask }
public static void Run() { // ExStart:DetectFlattenedPSD // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file using (PsdImage image = (PsdImage)Image.Load(dataDir + "samplePsd.psd")) { // Do processing, Get the true value if PSD is flatten and false in case the PSD is not flatten. Console.WriteLine(image.IsFlatten); } // ExEnd:DetectFlattenedPSD }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddThumbnailToJFIFSegment // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "aspose_out.psd")) { // Iterate over resources. foreach (var resource in image.ImageResources) { // Find thumbnail resource. Typically they are in the Jpeg file format. if (resource is ThumbnailResource || resource is Thumbnail4Resource) { // Adjust thumbnail data. var thumbnail = (ThumbnailResource)resource; var jfifData = new FileFormats.Jpeg.JFIFData(); var thumbnailImage = new PsdImage(100, 100); try { // Fill thumbnail data. int[] pixels = new int[thumbnailImage.Width * thumbnailImage.Height]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = i; } // Assign thumbnail data. thumbnailImage.SaveArgb32Pixels(thumbnailImage.Bounds, pixels); jfifData.Thumbnail = thumbnailImage; jfifData.XDensity = 1; jfifData.YDensity = 1; thumbnail.JpegOptions.Jfif = jfifData; } catch { thumbnailImage.Dispose(); throw; } } } image.Save(); } //ExEnd:AddThumbnailToJFIFSegment }
public static void Run() { //ExStart:MergePSDlayers // 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 + "layers.psd")) { // Create JPEG option class object, Set its properties and save image var jpgOptions = new JpegOptions(); psdImage.Save(dataDir + "MergePSDlayers_output.jpg", jpgOptions); } //ExEnd:MergePSDlayers }
public static void Run() { //ExStart:TiffOptionsConfiguration // 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 + "layers.psd")) { // Create an instance of TiffOptions while specifying desired format Passsing TiffExpectedFormat.TiffJpegRGB will set the compression to Jpeg and BitsPerPixel according to the RGB color space. TiffOptions options = new TiffOptions(TiffExpectedFormat.TiffJpegRgb); psdImage.Save(dataDir + "SampleTiff_out.tiff", options); } //ExEnd:TiffOptionsConfiguration }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSB(); //ExStart:PSBToPDF string sourceFileName = dataDir + "Simple.psb"; using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) { string outFileName = dataDir + "Simple.pdf"; image.Save(outFileName, new PdfOptions()); } //ExEnd:PSBToPDF }
public static void Run() { //ExStart:SettingResolution // 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 horizontal & vertical resolutions and Save the result on disc PngOptions options = new PngOptions(); options.ResolutionSettings = new ResolutionSetting(72, 96); psdImage.Save(dataDir + "SettingResolution_output.png", options); } //ExEnd:SettingResolution }
public static void Run() { // The path to the documents directory. string SourceDir = RunExamples.GetDataDir_PSD(); string OutputDir = RunExamples.GetDataDir_Output(); //ExStart:SupportEditingGlobalFontList //ExSummary:The following code demonstrates the ability to programmatically limit fonts using. string srcFile = Path.Combine(SourceDir, "fonts_com_updated.psd"); string output = Path.Combine(OutputDir, "etalon_fonts_com_updated.psd.png"); try { var fontList = new string[] { "Courier New", "Webdings", "Bookman Old Style" }; FontSettings.SetAllowedFonts(fontList); var myriadReplacement = new string[] { "Courier New", "Webdings", "Bookman Old Style" }; var calibriReplacement = new string[] { "Webdings", "Courier New", "Bookman Old Style" }; var arialReplacement = new string[] { "Bookman Old Style", "Courier New", "Webdings" }; var timesReplacement = new string[] { "Arial", "NotExistedFont", "Courier New" }; FontSettings.SetFontReplacements("MyriadPro-Regular", myriadReplacement); FontSettings.SetFontReplacements("Calibri", calibriReplacement); FontSettings.SetFontReplacements("Arial", arialReplacement); FontSettings.SetFontReplacements("Times New Roman", timesReplacement); using (PsdImage image = (PsdImage)Image.Load(srcFile)) { image.Save(output, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } finally { FontSettings.SetAllowedFonts(null); FontSettings.ClearFontReplacements(); } //ExEnd:SupportEditingGlobalFontList Console.WriteLine("SupportEditingGlobalFontList executed successfully"); File.Delete(output); }
public static void Run() { //ExStart:ResizeLayersWithVogkResourceAndVectorPaths // The path to the documents directory. string SourceDir = RunExamples.GetDataDir_PSD(); string OutputDir = RunExamples.GetDataDir_Output(); // This example shows how to resize layers with a Vogk and vector path resource in the PSD image float scaleX = 0.45f; float scaleY = 1.60f; string sourceFileName = Path.Combine(SourceDir, "vectorShapes.psd"); using (PsdImage image = (PsdImage)Image.Load(sourceFileName)) { for (int layerIndex = 1; layerIndex < image.Layers.Length; layerIndex++, scaleX += 0.25f, scaleY -= 0.25f) { var layer = image.Layers[layerIndex]; var newWidth = (int)Math.Round(layer.Width * scaleX); var newHeight = (int)Math.Round(layer.Height * scaleY); layer.Resize(newWidth, newHeight); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); string outputName = string.Format("resized_{0}_{1}_{2}", layerIndex, scaleX, scaleY); string outputPath = Path.Combine(OutputDir, outputName + ".psd"); string outputPngPath = Path.Combine(OutputDir, outputName + ".png"); image.Save(outputPath, new PsdOptions(image)); image.Save(outputPngPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } Console.WriteLine("ResizeLayersWithVogkResourceAndVectorPaths executed successfully"); //ExEnd:ResizeLayersWithVogkResourceAndVectorPaths string[] outputFiles = Directory.GetFiles(OutputDir, "resized_*", SearchOption.TopDirectoryOnly); foreach (var outputFile in outputFiles) { if (outputFile.EndsWith(".png") || outputFile.EndsWith(".psd")) { File.Delete(outputFile); } } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Opening(); //ExStart:LoadingImageFromStream string outputFilePath = dataDir + "PsdResult.psd"; var filesList = new string[] { "PsdExample.psd", "BmpExample.bmp", "GifExample.gif", "Jpeg2000Example.jpf", "JpegExample.jpg", "PngExample.png", "TiffExample.tif", }; using (var image = new PsdImage(200, 200)) { foreach (var fileName in filesList) { string filePath = dataDir + fileName; using (var stream = new FileStream(filePath, FileMode.Open)) { Layer layer = null; try { layer = new Layer(stream); image.AddLayer(layer); } catch (Exception e) { if (layer != null) { layer.Dispose(); } throw e; } } } image.Save(outputFilePath); } //ExEnd:LoadingImageFromStream }
public static void Run() { //ExStart:SupportForSmallCap // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); using (PsdImage image = Image.Load(dataDir + "smallCap.psd") as PsdImage) { image.Save(dataDir + "smallCap.png", new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } //ExEnd:SupportForSmallCap }
public static void Run() { //ExStart:ApplyFilterMethod // 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 PNG filter method and Save changes to the disc PngOptions options = new PngOptions(); options.FilterType = PngFilterType.Paeth; psdImage.Save(dataDir + "ApplyFilterMethod_out.png", options); } //ExEnd:ApplyFilterMethod }