public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:SupportOfInnerShadowLayerEffect string sourceFile = dataDir + "innershadow.psd"; string destName = dataDir + "innershadow_out.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; // Load an existing image into an instance of PsdImage class using (var image = (PsdImage)Image.Load(sourceFile, loadOptions)) { var layer = image.Layers[image.Layers.Length - 1]; var shadowEffect = (IShadowEffect)layer.BlendingOptions.Effects[0]; shadowEffect.Color = Color.Green; shadowEffect.Opacity = 128; shadowEffect.Distance = 1; shadowEffect.UseGlobalLight = false; shadowEffect.Size = 2; shadowEffect.Angle = 45; shadowEffect.Spread = 50; shadowEffect.Noise = 5; image.Save(destName, new PsdOptions(image)); } //ExEnd:SupportOfInnerShadowLayerEffect }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddStrokeLayer_Color // Stroke effect. FillType - Color. Example string sourceFileName = dataDir + "Stroke.psd"; string exportPath = dataDir + "StrokeGradientChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0]; if ((colorStroke.BlendMode != BlendMode.Normal) || (colorStroke.Opacity != 255) || (colorStroke.IsVisible != true)) { throw new Exception("Color stroke effect was read wrong"); } var fillSettings = (ColorFillSettings)colorStroke.FillSettings; if ((fillSettings.Color != Color.Black) || (fillSettings.FillType != FillType.Color)) { throw new Exception("Color stroke effect settings were read wrong"); } fillSettings.Color = Color.Yellow; colorStroke.Opacity = 127; colorStroke.BlendMode = BlendMode.Color; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) { var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0]; if ((colorStroke.BlendMode != BlendMode.Color) || (colorStroke.Opacity != 127) || (colorStroke.IsVisible != true)) { throw new Exception("Color stroke effect was read wrong"); } var fillSettings = (ColorFillSettings)colorStroke.FillSettings; if ((fillSettings.Color != Color.Yellow) || (fillSettings.FillType != FillType.Color)) { throw new Exception("Color stroke effect settings were read wrong"); } } //ExEnd:AddStrokeLayer_Color }
public static void Run() { //ExStart:RenderingDropShadow string dataDir = RunExamples.GetDataDir_PSD(); string sourceFileName = dataDir + "Shadow.psd"; string pngExportPath = dataDir + "Shadowchanged1.png"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var shadowEffect = (DropShadowEffect)(im.Layers[1].BlendingOptions.Effects[0]); Assert.AreEqual(Color.Black, shadowEffect.Color); Assert.AreEqual(255, shadowEffect.Opacity); Assert.AreEqual(3, shadowEffect.Distance); Assert.AreEqual(7, shadowEffect.Size); Assert.AreEqual(true, shadowEffect.UseGlobalLight); Assert.AreEqual(90, shadowEffect.Angle); Assert.AreEqual(0, shadowEffect.Spread); Assert.AreEqual(0, shadowEffect.Noise); // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } }
public static void Run() { //ExStart:PSBToJPG // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSB(); string[] sourceFileNames = new string[] { //Test files with layers "Little", "Simple", //Test files without layers "psb", "psb3" }; var options = new PsdLoadOptions(); foreach (var fileName in sourceFileNames) { var sourceFileName = dataDir + fileName + ".psb"; using (PsdImage image = (PsdImage)Image.Load(sourceFileName, options)) { // All jpeg and psd files must be readable image.Save(dataDir + fileName + "_output.jpg", new JpegOptions() { Quality = 95 }); image.Save(dataDir + fileName + "_output.psb"); } } //ExEnd:PSBToJPG }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:LoadPSDWithReadOnlyMode string sourceFileName = dataDir + "White 3D Text Effect.psd"; string outFileName = dataDir + "Exported.png"; LoadOptions loadOptions = new PsdLoadOptions() { ReadOnlyMode = true }; ImageOptionsBase saveOptions = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }; using (PsdImage image = (PsdImage)Image.Load(sourceFileName, loadOptions)) { image.Save(outFileName, saveOptions); } double memoryUsed = (GC.GetTotalMemory(false) / 1024.0) / 1024.0; // Memory usage must be less then 100 MB for this examples if (memoryUsed > 100) { throw new Exception("Usage of memory is too big"); } //ExEnd:LoadPSDWithReadOnlyMode }
public static void Run() { //ExStart:RenderingColorEffect string dataDir = RunExamples.GetDataDir_PSD(); string sourceFileName = dataDir + "ColorOverlay.psd"; string pngExportPath = dataDir + "ColorOverlayresult.png"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) //using (var im = (PsdImage)Image.Load(sourceFileName)) { var colorOverlay = (ColorOverlayEffect)(im.Layers[1].BlendingOptions.Effects[0]); Assert.AreEqual(Color.Red, colorOverlay.Color); Assert.AreEqual(153, colorOverlay.Opacity); // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:ColorOverLayEffect // ColorOverlay effect editing string sourceFileName = dataDir + "ColorOverlay.psd"; string psdPathAfterChange = dataDir + "ColorOverlayChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var colorOverlay = (ColorOverlayEffect)(im.Layers[1].BlendingOptions.Effects[0]); Assert.AreEqual(Color.Red, colorOverlay.Color); Assert.AreEqual(153, colorOverlay.Opacity); colorOverlay.Color = Color.Green; colorOverlay.Opacity = 128; im.Save(psdPathAfterChange); } //ExEnd:ColorOverLayEffect }
public static void Run() { string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddEffectAtRunTime // Add color overlay layer effect at runtime string sourceFileName = dataDir + "ThreeRegularLayers.psd"; string exportPath = dataDir + "ThreeRegularLayersChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var effect = im.Layers[1].BlendingOptions.AddColorOverlay(); effect.Color = Color.Green; effect.Opacity = 128; effect.BlendMode = BlendMode.Normal; im.Save(exportPath); } //ExEnd:AddEffectAtRunTime }
public static void Run() { string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:RenderingDropShadow string sourceFileName = dataDir + "Shadow.psd"; string pngExportPath = dataDir + "Shadowchanged1.png"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var shadowEffect = (DropShadowEffect)(im.Layers[1].BlendingOptions.Effects[0]); if ((shadowEffect.Color != Color.Black) || (shadowEffect.Opacity != 255) || (shadowEffect.Distance != 3) || (shadowEffect.Size != 7) || (shadowEffect.UseGlobalLight != true) || (shadowEffect.Angle != 90) || (shadowEffect.Spread != 0) || (shadowEffect.Noise != 0)) { throw new Exception("Shadow Effect properties were read wrong"); } // Save PNG var saveOptions = new PngOptions(); saveOptions.ColorType = PngColorType.TruecolorWithAlpha; im.Save(pngExportPath, saveOptions); } }
public static void Run() { //ExStart:SupportOfRGBColor // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Support of RGB Color mode with 16bits/channel (64 bits per color) string sourceFileName = dataDir + "inRgb16.psd"; string outputFilePathJpg = dataDir + "outRgb16.jpg"; string outputFilePathPsd = dataDir + "outRgb16.psd"; PsdLoadOptions options = new PsdLoadOptions(); using (PsdImage image = (PsdImage)Image.Load(sourceFileName, options)) { image.Save(outputFilePathPsd, new PsdOptions(image)); image.Save(outputFilePathJpg, new JpegOptions() { Quality = 100 }); } // Files must be opened without exception and must be readable for Photoshop using (Image image = Image.Load(outputFilePathPsd)) { } //ExEnd:SupportOfRGBColor }
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 dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddStrokeLayer_Color // Stroke effect. FillType - Color. Example string sourceFileName = dataDir + "Stroke.psd"; string exportPath = dataDir + "StrokeGradientChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0]; Assert.AreEqual(BlendMode.Normal, colorStroke.BlendMode); Assert.AreEqual(255, colorStroke.Opacity); Assert.AreEqual(true, colorStroke.IsVisible); var fillSettings = (ColorFillSettings)colorStroke.FillSettings; Assert.AreEqual(Color.Black, fillSettings.Color); Assert.AreEqual(FillType.Color, fillSettings.FillType); fillSettings.Color = Color.Yellow; colorStroke.Opacity = 127; colorStroke.BlendMode = BlendMode.Color; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) { var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0]; Assert.AreEqual(BlendMode.Color, colorStroke.BlendMode); Assert.AreEqual(127, colorStroke.Opacity); Assert.AreEqual(true, colorStroke.IsVisible); var fillSettings = (ColorFillSettings)colorStroke.FillSettings; Assert.AreEqual(Color.Yellow, fillSettings.Color); Assert.AreEqual(FillType.Color, fillSettings.FillType); } //ExEnd:AddStrokeLayer_Color }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:SupportShadowEffect string sourceFileName = dataDir + "Shadow.psd"; string psdPathAfterChange = dataDir + "ShadowChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var shadowEffect = (DropShadowEffect)(im.Layers[1].BlendingOptions.Effects[0]); if ((shadowEffect.Color != Color.Black) || (shadowEffect.Opacity != 255) || (shadowEffect.Distance != 3) || (shadowEffect.Size != 7) || (shadowEffect.UseGlobalLight != true) || (shadowEffect.Angle != 90) || (shadowEffect.Spread != 0) || (shadowEffect.Noise != 0)) { throw new Exception("Shadow Effect was read wrong"); } shadowEffect.Color = Color.Green; shadowEffect.Opacity = 128; shadowEffect.Distance = 11; shadowEffect.UseGlobalLight = false; shadowEffect.Size = 9; shadowEffect.Angle = 45; shadowEffect.Spread = 3; shadowEffect.Noise = 50; im.Save(psdPathAfterChange); } //ExEnd:SupportShadowEffect }
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 Run() { //ExStart:SupportShadowEffect // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); string sourceFileName = dataDir + "Shadow.psd"; string psdPathAfterChange = dataDir + "ShadowChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) //using (var im = (PsdImage)Image.Load(sourceFileName)) { var shadowEffect = (DropShadowEffect)(im.Layers[1].BlendingOptions.Effects[0]); Assert.AreEqual(Color.Black, shadowEffect.Color); Assert.AreEqual(255, shadowEffect.Opacity); Assert.AreEqual(3, shadowEffect.Distance); Assert.AreEqual(7, shadowEffect.Size); Assert.AreEqual(true, shadowEffect.UseGlobalLight); Assert.AreEqual(90, shadowEffect.Angle); Assert.AreEqual(0, shadowEffect.Spread); Assert.AreEqual(0, shadowEffect.Noise); shadowEffect.Color = Color.Green; shadowEffect.Opacity = 128; shadowEffect.Distance = 11; shadowEffect.UseGlobalLight = false; shadowEffect.Size = 9; shadowEffect.Angle = 45; shadowEffect.Spread = 3; shadowEffect.Noise = 50; im.Save(psdPathAfterChange); } }
public static void Run() { //ExStart:StrokeEffectWithColorFill // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Implement rendering of Stroke effect with Color Fill for export string sourceFileName = dataDir + "StrokeComplex.psd"; string exportPath = dataDir + "StrokeComplexRendering.psd"; string exportPathPng = dataDir + "StrokeComplexRendering.png"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { for (int i = 0; i < im.Layers.Length; i++) { var effect = (StrokeEffect)im.Layers[i].BlendingOptions.Effects[0]; var settings = (ColorFillSettings)effect.FillSettings; settings.Color = Color.DeepPink; } // Save psd im.Save(exportPath, new PsdOptions()); // Save png im.Save(exportPathPng, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } //ExEnd:StrokeEffectWithColorFill }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddStrokeLayer_Pattern // Stroke effect. FillType - Pattern. Example string sourceFileName = dataDir + "Stroke.psd"; string exportPath = dataDir + "StrokePatternChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; // Preparing new data var newPattern = new int[] { Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), }; var newPatternBounds = new Rectangle(0, 0, 4, 4); var guid = Guid.NewGuid(); using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0]; Assert.AreEqual(BlendMode.Normal, patternStroke.BlendMode); Assert.AreEqual(255, patternStroke.Opacity); Assert.AreEqual(true, patternStroke.IsVisible); var fillSettings = (PatternFillSettings)patternStroke.FillSettings; Assert.AreEqual(FillType.Pattern, fillSettings.FillType); patternStroke.Opacity = 127; patternStroke.BlendMode = BlendMode.Color; PattResource resource; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; resource.PatternId = guid.ToString(); resource.Name = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9\0"; resource.SetPattern(newPattern, newPatternBounds); } } ((PatternFillSettings)patternStroke.FillSettings).PatternName = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9\0"; ((PatternFillSettings)patternStroke.FillSettings).PatternId = guid.ToString() + "\0"; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0]; PattResource resource = null; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; } } if (resource == null) { throw new Exception("PattResource not found"); } try { // Check the pattern data Assert.AreEqual(newPattern, resource.PatternData); Assert.AreEqual(newPatternBounds, new Rectangle(0, 0, resource.Width, resource.Height)); Assert.AreEqual(guid.ToString(), resource.PatternId); Assert.AreEqual(BlendMode.Color, patternStroke.BlendMode); Assert.AreEqual(127, patternStroke.Opacity); Assert.AreEqual(true, patternStroke.IsVisible); var fillSettings = (PatternFillSettings)patternStroke.FillSettings; Assert.AreEqual(FillType.Pattern, fillSettings.FillType); } catch (Exception e) { String ex = e.StackTrace; } } //ExEnd:AddStrokeLayer_Pattern }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddStrokeLayer_Gradient // Stroke effect. FillType - Gradient. Example string sourceFileName = dataDir + "Stroke.psd"; string exportPath = dataDir + "StrokeGradientChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0]; Assert.AreEqual(BlendMode.Normal, gradientStroke.BlendMode); Assert.AreEqual(255, gradientStroke.Opacity); Assert.AreEqual(true, gradientStroke.IsVisible); var fillSettings = (GradientFillSettings)gradientStroke.FillSettings; Assert.AreEqual(Color.Black, fillSettings.Color); Assert.AreEqual(FillType.Gradient, fillSettings.FillType); Assert.AreEqual(true, fillSettings.AlignWithLayer); Assert.AreEqual(GradientType.Linear, fillSettings.GradientType); Assert.IsTrue(Math.Abs(90 - fillSettings.Angle) < 0.001, "Angle is incorrect"); Assert.AreEqual(false, fillSettings.Dither); Assert.IsTrue(Math.Abs(0 - fillSettings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect"); Assert.IsTrue(Math.Abs(0 - fillSettings.VerticalOffset) < 0.001, "Vertical offset is incorrect"); Assert.AreEqual(false, fillSettings.Reverse); // Color Points var colorPoints = fillSettings.ColorPoints; Assert.AreEqual(2, colorPoints.Length); Assert.AreEqual(Color.Black, colorPoints[0].Color); Assert.AreEqual(0, colorPoints[0].Location); Assert.AreEqual(50, colorPoints[0].MedianPointLocation); Assert.AreEqual(Color.White, colorPoints[1].Color); Assert.AreEqual(4096, colorPoints[1].Location); Assert.AreEqual(50, colorPoints[1].MedianPointLocation); // Transparency points var transparencyPoints = fillSettings.TransparencyPoints; Assert.AreEqual(2, transparencyPoints.Length); Assert.AreEqual(0, transparencyPoints[0].Location); Assert.AreEqual(50, transparencyPoints[0].MedianPointLocation); Assert.AreEqual(100, transparencyPoints[0].Opacity); Assert.AreEqual(4096, transparencyPoints[1].Location); Assert.AreEqual(50, transparencyPoints[1].MedianPointLocation); Assert.AreEqual(100, transparencyPoints[1].Opacity); // Test editing fillSettings.Color = Color.Green; gradientStroke.Opacity = 127; gradientStroke.BlendMode = BlendMode.Color; fillSettings.AlignWithLayer = false; fillSettings.GradientType = GradientType.Radial; fillSettings.Angle = 45; fillSettings.Dither = true; fillSettings.HorizontalOffset = 15; fillSettings.VerticalOffset = 11; fillSettings.Reverse = true; // Add new color point var colorPoint = fillSettings.AddColorPoint(); colorPoint.Color = Color.Green; colorPoint.Location = 4096; colorPoint.MedianPointLocation = 75; // Change location of previous point fillSettings.ColorPoints[1].Location = 1899; // Add new transparency point var transparencyPoint = fillSettings.AddTransparencyPoint(); transparencyPoint.Opacity = 25; transparencyPoint.MedianPointLocation = 25; transparencyPoint.Location = 4096; // Change location of previous transparency point fillSettings.TransparencyPoints[1].Location = 2411; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) { var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0]; Assert.AreEqual(BlendMode.Color, gradientStroke.BlendMode); Assert.AreEqual(127, gradientStroke.Opacity); Assert.AreEqual(true, gradientStroke.IsVisible); var fillSettings = (GradientFillSettings)gradientStroke.FillSettings; Assert.AreEqual(Color.Green, fillSettings.Color); Assert.AreEqual(FillType.Gradient, fillSettings.FillType); // Check color points Assert.AreEqual(3, fillSettings.ColorPoints.Length); var point = fillSettings.ColorPoints[0]; Assert.AreEqual(50, point.MedianPointLocation); Assert.AreEqual(Color.Black, point.Color); Assert.AreEqual(0, point.Location); point = fillSettings.ColorPoints[1]; Assert.AreEqual(50, point.MedianPointLocation); Assert.AreEqual(Color.White, point.Color); Assert.AreEqual(1899, point.Location); point = fillSettings.ColorPoints[2]; Assert.AreEqual(75, point.MedianPointLocation); Assert.AreEqual(Color.Green, point.Color); Assert.AreEqual(4096, point.Location); // Check transparent points Assert.AreEqual(3, fillSettings.TransparencyPoints.Length); var transparencyPoint = fillSettings.TransparencyPoints[0]; Assert.AreEqual(50, transparencyPoint.MedianPointLocation); Assert.AreEqual(100, transparencyPoint.Opacity); Assert.AreEqual(0, transparencyPoint.Location); transparencyPoint = fillSettings.TransparencyPoints[1]; Assert.AreEqual(50, transparencyPoint.MedianPointLocation); Assert.AreEqual(100, transparencyPoint.Opacity); Assert.AreEqual(2411, transparencyPoint.Location); transparencyPoint = fillSettings.TransparencyPoints[2]; Assert.AreEqual(25, transparencyPoint.MedianPointLocation); Assert.AreEqual(25, transparencyPoint.Opacity); Assert.AreEqual(4096, transparencyPoint.Location); } //ExEnd:AddStrokeLayer_Gradient }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddGradientEffects // Gradient overlay effect. Example string sourceFileName = dataDir + "GradientOverlay.psd"; string exportPath = dataDir + "GradientOverlayChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var gradientOverlay = (GradientOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; Assert.AreEqual(BlendMode.Normal, gradientOverlay.BlendMode); Assert.AreEqual(255, gradientOverlay.Opacity); Assert.AreEqual(true, gradientOverlay.IsVisible); var settings = gradientOverlay.Settings; Assert.AreEqual(Color.Empty, settings.Color); Assert.AreEqual(FillType.Gradient, settings.FillType); Assert.AreEqual(true, settings.AlignWithLayer); Assert.AreEqual(GradientType.Linear, settings.GradientType); Assert.IsTrue(Math.Abs(33 - settings.Angle) < 0.001, "Angle is incorrect"); Assert.AreEqual(false, settings.Dither); Assert.IsTrue(Math.Abs(129 - settings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect"); Assert.IsTrue(Math.Abs(156 - settings.VerticalOffset) < 0.001, "Vertical offset is incorrect"); Assert.AreEqual(false, settings.Reverse); // Color Points var colorPoints = settings.ColorPoints; Assert.AreEqual(3, colorPoints.Length); Assert.AreEqual(Color.FromArgb(9, 0, 178), colorPoints[0].Color); Assert.AreEqual(0, colorPoints[0].Location); Assert.AreEqual(50, colorPoints[0].MedianPointLocation); Assert.AreEqual(Color.Red, colorPoints[1].Color); Assert.AreEqual(2048, colorPoints[1].Location); Assert.AreEqual(50, colorPoints[1].MedianPointLocation); Assert.AreEqual(Color.FromArgb(255, 252, 0), colorPoints[2].Color); Assert.AreEqual(4096, colorPoints[2].Location); Assert.AreEqual(50, colorPoints[2].MedianPointLocation); // Transparency points var transparencyPoints = settings.TransparencyPoints; Assert.AreEqual(2, transparencyPoints.Length); Assert.AreEqual(0, transparencyPoints[0].Location); Assert.AreEqual(50, transparencyPoints[0].MedianPointLocation); Assert.AreEqual(100, transparencyPoints[0].Opacity); Assert.AreEqual(4096, transparencyPoints[1].Location); Assert.AreEqual(50, transparencyPoints[1].MedianPointLocation); Assert.AreEqual(100, transparencyPoints[1].Opacity); // Test editing settings.Color = Color.Green; gradientOverlay.Opacity = 193; gradientOverlay.BlendMode = BlendMode.Lighten; settings.AlignWithLayer = false; settings.GradientType = GradientType.Radial; settings.Angle = 45; settings.Dither = true; settings.HorizontalOffset = 15; settings.VerticalOffset = 11; settings.Reverse = true; // Add new color point var colorPoint = settings.AddColorPoint(); colorPoint.Color = Color.Green; colorPoint.Location = 4096; colorPoint.MedianPointLocation = 75; // Change location of previous point settings.ColorPoints[2].Location = 3000; // Add new transparency point var transparencyPoint = settings.AddTransparencyPoint(); transparencyPoint.Opacity = 25; transparencyPoint.MedianPointLocation = 25; transparencyPoint.Location = 4096; // Change location of previous transparency point settings.TransparencyPoints[1].Location = 2315; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var gradientOverlay = (GradientOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; try { Assert.AreEqual(BlendMode.Lighten, gradientOverlay.BlendMode); Assert.AreEqual(193, gradientOverlay.Opacity); Assert.AreEqual(true, gradientOverlay.IsVisible); var fillSettings = gradientOverlay.Settings; Assert.AreEqual(Color.Empty, fillSettings.Color); Assert.AreEqual(FillType.Gradient, fillSettings.FillType); // Check color points Assert.AreEqual(4, fillSettings.ColorPoints.Length); var point = fillSettings.ColorPoints[0]; Assert.AreEqual(50, point.MedianPointLocation); Assert.AreEqual(Color.FromArgb(9, 0, 178), point.Color); Assert.AreEqual(0, point.Location); point = fillSettings.ColorPoints[1]; Assert.AreEqual(50, point.MedianPointLocation); Assert.AreEqual(Color.Red, point.Color); Assert.AreEqual(2048, point.Location); point = fillSettings.ColorPoints[2]; Assert.AreEqual(50, point.MedianPointLocation); Assert.AreEqual(Color.FromArgb(255, 252, 0), point.Color); Assert.AreEqual(3000, point.Location); point = fillSettings.ColorPoints[3]; Assert.AreEqual(75, point.MedianPointLocation); Assert.AreEqual(Color.Green, point.Color); Assert.AreEqual(4096, point.Location); // Check transparent points Assert.AreEqual(3, fillSettings.TransparencyPoints.Length); var transparencyPoint = fillSettings.TransparencyPoints[0]; Assert.AreEqual(50, transparencyPoint.MedianPointLocation); Assert.AreEqual(100, transparencyPoint.Opacity); Assert.AreEqual(0, transparencyPoint.Location); transparencyPoint = fillSettings.TransparencyPoints[1]; Assert.AreEqual(50, transparencyPoint.MedianPointLocation); Assert.AreEqual(100, transparencyPoint.Opacity); Assert.AreEqual(2315, transparencyPoint.Location); transparencyPoint = fillSettings.TransparencyPoints[2]; Assert.AreEqual(25, transparencyPoint.MedianPointLocation); Assert.AreEqual(25, transparencyPoint.Opacity); Assert.AreEqual(4096, transparencyPoint.Location); } catch (Exception e) { String ex = e.StackTrace; } } //ExEnd:AddGradientEffects }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddPatternEffects // Pattern overlay effect. Example string sourceFileName = dataDir + "PatternOverlay.psd"; string exportPath = dataDir + "PatternOverlayChanged.psd"; var newPattern = new int[] { Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), }; var newPatternBounds = new Rectangle(0, 0, 4, 2); var guid = Guid.NewGuid(); var newPatternName = "$$$/Presets/Patterns/Pattern=Some new pattern name\0"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var patternOverlay = (PatternOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; Assert.AreEqual(BlendMode.Normal, patternOverlay.BlendMode); Assert.AreEqual(127, patternOverlay.Opacity); Assert.AreEqual(true, patternOverlay.IsVisible); var settings = patternOverlay.Settings; Assert.AreEqual(Color.Empty, settings.Color); Assert.AreEqual(FillType.Pattern, settings.FillType); Assert.AreEqual("85163837-eb9e-5b43-86fb-e6d5963ea29a\0", settings.PatternId); Assert.AreEqual("$$$/Presets/Patterns/OpticalSquares=Optical Squares\0", settings.PatternName); Assert.AreEqual(null, settings.PointType); Assert.AreEqual(100, settings.Scale); Assert.AreEqual(false, settings.Linked); Assert.IsTrue(Math.Abs(0 - settings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect"); Assert.IsTrue(Math.Abs(0 - settings.VerticalOffset) < 0.001, "Vertical offset is incorrect"); // Test editing settings.Color = Color.Green; patternOverlay.Opacity = 193; patternOverlay.BlendMode = BlendMode.Difference; settings.HorizontalOffset = 15; settings.VerticalOffset = 11; PattResource resource; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; resource.PatternId = guid.ToString(); resource.Name = newPatternName; resource.SetPattern(newPattern, newPatternBounds); } } settings.PatternName = newPatternName; settings.PatternId = guid.ToString() + "\0"; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var patternOverlay = (PatternOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; try { Assert.AreEqual(BlendMode.Difference, patternOverlay.BlendMode); Assert.AreEqual(193, patternOverlay.Opacity); Assert.AreEqual(true, patternOverlay.IsVisible); var fillSettings = patternOverlay.Settings; Assert.AreEqual(Color.Empty, fillSettings.Color); Assert.AreEqual(FillType.Pattern, fillSettings.FillType); PattResource resource = null; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; } } if (resource == null) { throw new Exception("PattResource not found"); } // Check the pattern data Assert.AreEqual(newPattern, resource.PatternData); Assert.AreEqual(newPatternBounds, new Rectangle(0, 0, resource.Width, resource.Height)); Assert.AreEqual(guid.ToString(), resource.PatternId); Assert.AreEqual(newPatternName, resource.Name); } catch (Exception e) { String ex = e.StackTrace; } } //ExEnd:AddPatternEffects }
public static void Run() { // The path to the documents directory. string SourceDir = RunExamples.GetDataDir_PSD(); string OutputDir = RunExamples.GetDataDir_Output(); //ExStart:AddGradientEffects void AssertIsTrue(bool condition, string message = "Assertion fails") { if (!condition) { throw new FormatException(message); } } // Gradient overlay effect. Example string sourceFileName = Path.Combine(SourceDir, "GradientOverlay.psd"); string exportPath = Path.Combine(OutputDir, "GradientOverlayChanged.psd"); var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var gradientOverlay = (GradientOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; AssertIsTrue(gradientOverlay.BlendMode == BlendMode.Normal); AssertIsTrue(gradientOverlay.Opacity == 255); AssertIsTrue(gradientOverlay.IsVisible == true); var settings = gradientOverlay.Settings; AssertIsTrue(settings.Color == Color.Empty); AssertIsTrue(settings.FillType == FillType.Gradient); AssertIsTrue(settings.AlignWithLayer == true); AssertIsTrue(settings.GradientType == GradientType.Linear); AssertIsTrue(Math.Abs(33 - settings.Angle) < 0.001, "Angle is incorrect"); AssertIsTrue(settings.Dither == false); AssertIsTrue(Math.Abs(129 - settings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect"); AssertIsTrue(Math.Abs(156 - settings.VerticalOffset) < 0.001, "Vertical offset is incorrect"); AssertIsTrue(settings.Reverse == false); // Color Points var colorPoints = settings.ColorPoints; AssertIsTrue(colorPoints.Length == 3); AssertIsTrue(colorPoints[0].Color == Color.FromArgb(9, 0, 178)); AssertIsTrue(colorPoints[0].Location == 0); AssertIsTrue(colorPoints[0].MedianPointLocation == 50); AssertIsTrue(colorPoints[1].Color == Color.Red); AssertIsTrue(colorPoints[1].Location == 2048); AssertIsTrue(colorPoints[1].MedianPointLocation == 50); AssertIsTrue(colorPoints[2].Color == Color.FromArgb(255, 252, 0)); AssertIsTrue(colorPoints[2].Location == 4096); AssertIsTrue(colorPoints[2].MedianPointLocation == 50); // Transparency points var transparencyPoints = settings.TransparencyPoints; AssertIsTrue(transparencyPoints.Length == 2); AssertIsTrue(transparencyPoints[0].Location == 0); AssertIsTrue(transparencyPoints[0].MedianPointLocation == 50); AssertIsTrue(transparencyPoints[0].Opacity == 100); AssertIsTrue(transparencyPoints[1].Location == 4096); AssertIsTrue(transparencyPoints[1].MedianPointLocation == 50); AssertIsTrue(transparencyPoints[1].Opacity == 100); // Test editing settings.Color = Color.Green; gradientOverlay.Opacity = 193; gradientOverlay.BlendMode = BlendMode.Lighten; settings.AlignWithLayer = false; settings.GradientType = GradientType.Radial; settings.Angle = 45; settings.Dither = true; settings.HorizontalOffset = 15; settings.VerticalOffset = 11; settings.Reverse = true; // Add new color point var colorPoint = settings.AddColorPoint(); colorPoint.Color = Color.Green; colorPoint.Location = 4096; colorPoint.MedianPointLocation = 75; // Change location of previous point settings.ColorPoints[2].Location = 3000; // Add new transparency point var transparencyPoint = settings.AddTransparencyPoint(); transparencyPoint.Opacity = 25; transparencyPoint.MedianPointLocation = 25; transparencyPoint.Location = 4096; // Change location of previous transparency point settings.TransparencyPoints[1].Location = 2315; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) { var gradientOverlay = (GradientOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; try { AssertIsTrue(gradientOverlay.BlendMode == BlendMode.Lighten); AssertIsTrue(gradientOverlay.Opacity == 193); AssertIsTrue(gradientOverlay.IsVisible == true); var fillSettings = gradientOverlay.Settings; AssertIsTrue(fillSettings.Color == Color.Empty); AssertIsTrue(fillSettings.FillType == FillType.Gradient); // Check color points AssertIsTrue(fillSettings.ColorPoints.Length == 4); var point = fillSettings.ColorPoints[0]; AssertIsTrue(point.MedianPointLocation == 50); AssertIsTrue(point.Color == Color.FromArgb(9, 0, 178)); AssertIsTrue(point.Location == 0); point = fillSettings.ColorPoints[1]; AssertIsTrue(point.MedianPointLocation == 50); AssertIsTrue(point.Color == Color.Red); AssertIsTrue(point.Location == 2048); point = fillSettings.ColorPoints[2]; AssertIsTrue(point.MedianPointLocation == 50); AssertIsTrue(point.Color == Color.FromArgb(255, 252, 0)); AssertIsTrue(point.Location == 3000); point = fillSettings.ColorPoints[3]; AssertIsTrue(point.MedianPointLocation == 75); AssertIsTrue(point.Color == Color.Green); AssertIsTrue(point.Location == 4096); // Check transparent points AssertIsTrue(fillSettings.TransparencyPoints.Length == 3); var transparencyPoint = fillSettings.TransparencyPoints[0]; AssertIsTrue(transparencyPoint.MedianPointLocation == 50); AssertIsTrue(transparencyPoint.Opacity == 100.0); AssertIsTrue(transparencyPoint.Location == 0); transparencyPoint = fillSettings.TransparencyPoints[1]; AssertIsTrue(transparencyPoint.MedianPointLocation == 50); AssertIsTrue(transparencyPoint.Opacity == 100.0); AssertIsTrue(transparencyPoint.Location == 2315); transparencyPoint = fillSettings.TransparencyPoints[2]; AssertIsTrue(transparencyPoint.MedianPointLocation == 25); AssertIsTrue(transparencyPoint.Opacity == 25.0); AssertIsTrue(transparencyPoint.Location == 4096); } catch (Exception e) { string ex = e.StackTrace; } } //ExEnd:AddGradientEffects File.Delete(exportPath); }
public static void Run() { // The path to the documents directory. string SourceDir = RunExamples.GetDataDir_PSD(); string OutputDir = RunExamples.GetDataDir_Output(); //ExStart:AddStrokeLayer_Pattern // Stroke effect. FillType - Pattern. Example string sourceFileName = Path.Combine(SourceDir, "Stroke.psd"); string exportPath = Path.Combine(OutputDir, "StrokePatternChanged.psd"); var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; // Preparing new data var newPattern = new int[] { Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), }; var newPatternBounds = new Rectangle(0, 0, 4, 4); var guid = Guid.NewGuid(); using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0]; var fillSettings = (PatternFillSettings)patternStroke.FillSettings; if ((patternStroke.BlendMode != BlendMode.Normal) || (patternStroke.Opacity != 255) || (patternStroke.IsVisible != true) || (fillSettings.FillType != FillType.Pattern)) { throw new Exception("Pattern effect properties were read wrong"); } patternStroke.Opacity = 127; patternStroke.BlendMode = BlendMode.Color; PattResource resource; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; var patternData = resource.Patterns[0]; patternData.PatternId = guid.ToString(); patternData.Name = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9"; patternData.SetPattern(newPattern, newPatternBounds); } } var settings = (PatternFillSettings)patternStroke.FillSettings; settings.PatternName = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9"; settings.PatternId = guid.ToString(); settings.PatternData = newPattern; settings.PatternWidth = newPatternBounds.Width; settings.PatternHeight = newPatternBounds.Height; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) { var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0]; PattResource resource = null; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; } } if (resource == null) { throw new Exception("PattResource not found"); } try { // Check the pattern data var fillSettings = (PatternFillSettings)patternStroke.FillSettings; var patternData = resource.Patterns[0]; if ((newPatternBounds != new Rectangle(0, 0, patternData.Width, patternData.Height)) || (patternData.PatternId != guid.ToString()) || (patternStroke.BlendMode != BlendMode.Color) || (patternStroke.Opacity != 127) || (patternStroke.IsVisible != true) || (fillSettings.FillType != FillType.Pattern)) { throw new Exception("Pattern stroke effect properties were read wrong"); } } catch (Exception e) { string ex = e.StackTrace; } } //ExEnd:AddStrokeLayer_Pattern File.Delete(exportPath); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddStrokeLayer_Gradient // Stroke effect. FillType - Gradient. Example void AssertIsTrue(bool condition, string message = "Assertion fails") { if (!condition) { throw new FormatException(message); } } string sourceFileName = dataDir + "Stroke.psd"; string exportPath = dataDir + "StrokeGradientChanged.psd"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0]; AssertIsTrue(gradientStroke.BlendMode == BlendMode.Normal); AssertIsTrue(gradientStroke.Opacity == 255); AssertIsTrue(gradientStroke.IsVisible); var fillSettings = (GradientFillSettings)gradientStroke.FillSettings; AssertIsTrue(fillSettings.Color == Color.Black); AssertIsTrue(fillSettings.FillType == FillType.Gradient); AssertIsTrue(fillSettings.AlignWithLayer); AssertIsTrue(fillSettings.GradientType == GradientType.Linear); AssertIsTrue(Math.Abs(90 - fillSettings.Angle) < 0.001, "Angle is incorrect"); AssertIsTrue(fillSettings.Dither == false); AssertIsTrue(Math.Abs(0 - fillSettings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect"); AssertIsTrue(Math.Abs(0 - fillSettings.VerticalOffset) < 0.001, "Vertical offset is incorrect"); AssertIsTrue(fillSettings.Reverse == false); // Color Points var colorPoints = fillSettings.ColorPoints; AssertIsTrue(colorPoints.Length == 2); AssertIsTrue(colorPoints[0].Color == Color.Black); AssertIsTrue(colorPoints[0].Location == 0); AssertIsTrue(colorPoints[0].MedianPointLocation == 50); AssertIsTrue(colorPoints[1].Color == Color.White); AssertIsTrue(colorPoints[1].Location == 4096); AssertIsTrue(colorPoints[1].MedianPointLocation == 50); // Transparency points var transparencyPoints = fillSettings.TransparencyPoints; AssertIsTrue(transparencyPoints.Length == 2); AssertIsTrue(transparencyPoints[0].Location == 0); AssertIsTrue(transparencyPoints[0].MedianPointLocation == 50); AssertIsTrue(transparencyPoints[0].Opacity == 100); AssertIsTrue(transparencyPoints[1].Location == 4096); AssertIsTrue(transparencyPoints[1].MedianPointLocation == 50); AssertIsTrue(transparencyPoints[1].Opacity == 100); // Test editing fillSettings.Color = Color.Green; gradientStroke.Opacity = 127; gradientStroke.BlendMode = BlendMode.Color; fillSettings.AlignWithLayer = false; fillSettings.GradientType = GradientType.Radial; fillSettings.Angle = 45; fillSettings.Dither = true; fillSettings.HorizontalOffset = 15; fillSettings.VerticalOffset = 11; fillSettings.Reverse = true; // Add new color point var colorPoint = fillSettings.AddColorPoint(); colorPoint.Color = Color.Green; colorPoint.Location = 4096; colorPoint.MedianPointLocation = 75; // Change location of previous point fillSettings.ColorPoints[1].Location = 1899; // Add new transparency point var transparencyPoint = fillSettings.AddTransparencyPoint(); transparencyPoint.Opacity = 25; transparencyPoint.MedianPointLocation = 25; transparencyPoint.Location = 4096; // Change location of previous transparency point fillSettings.TransparencyPoints[1].Location = 2411; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(exportPath, loadOptions)) { var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0]; if ((gradientStroke.BlendMode != BlendMode.Color) || (gradientStroke.Opacity != 127) || (gradientStroke.IsVisible != true)) { throw new Exception("Assertion of Gradient Stroke fails"); } var fillSettings = (GradientFillSettings)gradientStroke.FillSettings; if ((fillSettings.Color != Color.Green) || (fillSettings.FillType != FillType.Gradient) || fillSettings.ColorPoints.Length != 3) { throw new Exception("Assertion fails"); } // Check color points var point = fillSettings.ColorPoints[0]; AssertIsTrue(point.MedianPointLocation == 50); AssertIsTrue(point.Color == Color.Black); AssertIsTrue(point.Location == 0); point = fillSettings.ColorPoints[1]; AssertIsTrue(point.MedianPointLocation == 50); AssertIsTrue(point.Color == Color.White); AssertIsTrue(point.Location == 1899); point = fillSettings.ColorPoints[2]; AssertIsTrue(point.MedianPointLocation == 75); AssertIsTrue(point.Color == Color.Green); AssertIsTrue(point.Location == 4096); // Check transparent points AssertIsTrue(fillSettings.TransparencyPoints.Length == 3); var transparencyPoint = fillSettings.TransparencyPoints[0]; AssertIsTrue(transparencyPoint.MedianPointLocation == 50); AssertIsTrue(transparencyPoint.Opacity == 100); AssertIsTrue(transparencyPoint.Location == 0); transparencyPoint = fillSettings.TransparencyPoints[1]; AssertIsTrue(transparencyPoint.MedianPointLocation == 50); AssertIsTrue(transparencyPoint.Opacity == 100); AssertIsTrue(transparencyPoint.Location == 2411); transparencyPoint = fillSettings.TransparencyPoints[2]; AssertIsTrue(transparencyPoint.MedianPointLocation == 25); AssertIsTrue(transparencyPoint.Opacity == 25); AssertIsTrue(transparencyPoint.Location == 4096); } //ExEnd:AddStrokeLayer_Gradient }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AddPatternEffects // Pattern overlay effect. Example string sourceFileName = dataDir + "PatternOverlay.psd"; string exportPath = dataDir + "PatternOverlayChanged.psd"; var newPattern = new int[] { Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(), Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(), }; var newPatternBounds = new Rectangle(0, 0, 4, 2); var guid = Guid.NewGuid(); var newPatternName = "$$$/Presets/Patterns/Pattern=Some new pattern name\0"; var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true }; using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var patternOverlay = (PatternOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; if ((patternOverlay.BlendMode != BlendMode.Normal) || (patternOverlay.Opacity != 127) || (patternOverlay.IsVisible != true) ) { throw new Exception("Pattern overlay effect properties were read wrong"); } var settings = patternOverlay.Settings; if ((settings.Color != Color.Empty) || (settings.FillType != FillType.Pattern) || (settings.PatternId != "85163837-eb9e-5b43-86fb-e6d5963ea29a\0") || (settings.PatternName != "$$$/Presets/Patterns/OpticalSquares=Optical Squares\0") || (settings.PointType != null) || (Math.Abs(settings.Scale - 100) > 0.001) || (settings.Linked != true) || (Math.Abs(0 - settings.HorizontalOffset) > 0.001) || (Math.Abs(0 - settings.VerticalOffset) > 0.001)) { throw new Exception("Pattern overlay effect settings were read wrong"); } // Test editing settings.Color = Color.Green; patternOverlay.Opacity = 193; patternOverlay.BlendMode = BlendMode.Difference; settings.HorizontalOffset = 15; settings.VerticalOffset = 11; PattResource resource; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; resource.PatternId = guid.ToString(); resource.Name = newPatternName; resource.SetPattern(newPattern, newPatternBounds); } } settings.PatternName = newPatternName; settings.PatternId = guid.ToString() + "\0"; im.Save(exportPath); } // Test file after edit using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions)) { var patternOverlay = (PatternOverlayEffect)im.Layers[1].BlendingOptions.Effects[0]; try { if ((patternOverlay.BlendMode != BlendMode.Difference) || (patternOverlay.Opacity != 193) || (patternOverlay.IsVisible != true)) { throw new Exception("Pattern overlay effect properties were read wrong"); } var fillSettings = patternOverlay.Settings; if ((fillSettings.Color != Color.Empty) || (fillSettings.FillType != FillType.Pattern)) { throw new Exception("Pattern overlay effect settings were read wrong"); } PattResource resource = null; foreach (var globalLayerResource in im.GlobalLayerResources) { if (globalLayerResource is PattResource) { resource = (PattResource)globalLayerResource; } } if (resource == null) { throw new Exception("PattResource not found"); } // Check the pattern data if ((resource.PatternData != newPattern) || (newPatternBounds != new Rectangle(0, 0, resource.Width, resource.Height)) || (resource.PatternId != guid.ToString()) || (resource.Name != newPatternName) ) { throw new Exception("Pattern was set wrong"); } } catch (Exception e) { string ex = e.StackTrace; } } //ExEnd:AddPatternEffects }