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: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_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: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 }