public static void Run() { // The path to the documents directory. string OutputDir = RunExamples.GetDataDir_Output(); //ExStart:AddingFillLayerAtRuntime //ExSummary:The following example demonstrates how to add the FillLayer type layer at runtime. string outputFilePath = Path.Combine(OutputDir, "output.psd"); using (var image = new PsdImage(100, 100)) { FillLayer colorFillLayer = FillLayer.CreateInstance(FillType.Color); colorFillLayer.DisplayName = "Color Fill Layer"; image.AddLayer(colorFillLayer); FillLayer gradientFillLayer = FillLayer.CreateInstance(FillType.Gradient); gradientFillLayer.DisplayName = "Gradient Fill Layer"; image.AddLayer(gradientFillLayer); FillLayer patternFillLayer = FillLayer.CreateInstance(FillType.Pattern); patternFillLayer.DisplayName = "Pattern Fill Layer"; patternFillLayer.Opacity = 50; image.AddLayer(patternFillLayer); image.Save(outputFilePath); } //ExEnd:AddingFillLayerAtRuntime Console.WriteLine("AddingFillLayerAtRuntime executed successfully"); }
//ExStart:ClassesToManipulateVectorPathObjects //ExSummary:The following code example provides classes to manipulate the vector path objects and demonstrates how to use those classes. private static void CreatingVectorPathExample(string outputPsd = "outputPsd.psd") { using (var psdImage = (PsdImage)Image.Create(new PsdOptions() { Source = new StreamSource(new MemoryStream()), }, 500, 500)) { FillLayer layer = FillLayer.CreateInstance(FillType.Color); psdImage.AddLayer(layer); VectorPath vectorPath = VectorDataProvider.CreateVectorPathForLayer(layer); vectorPath.FillColor = Color.IndianRed; PathShape shape = new PathShape(); shape.Points.Add(new BezierKnot(new PointF(50, 150), true)); shape.Points.Add(new BezierKnot(new PointF(100, 200), true)); shape.Points.Add(new BezierKnot(new PointF(0, 200), true)); vectorPath.Shapes.Add(shape); VectorDataProvider.UpdateLayerFromVectorPath(layer, vectorPath, true); psdImage.Save(outputPsd); } }
public static void Run() { // The path to the documents directory. string outputDir = RunExamples.GetDataDir_Output(); //ExStart:SupportOfEditFontNameInTextPortionStyle //ExSummary:The following code demonstrate the ability to change font name at portion style. string outputFilePng = outputDir + "result_fontEditTest.png"; string outputFilePsd = outputDir + "fontEditTest.psd"; void AssertAreEqual(object expected, object actual) { if (!object.Equals(expected, actual)) { throw new Exception("Objects are not equal."); } } using (var image = new PsdImage(500, 500)) { FillLayer backgroundFillLayer = FillLayer.CreateInstance(FillType.Color); ((IColorFillSettings)backgroundFillLayer.FillSettings).Color = Color.White; image.AddLayer(backgroundFillLayer); TextLayer textLayer = image.AddTextLayer("Text 1", new Rectangle(10, 35, image.Width, 35)); ITextPortion firstPortion = textLayer.TextData.Items[0]; firstPortion.Style.FontName = FontSettings.GetAdobeFontName("Comic Sans MS"); var secondPortion = textLayer.TextData.ProducePortion(); secondPortion.Text = "Text 2"; secondPortion.Paragraph.Apply(firstPortion.Paragraph); secondPortion.Style.Apply(firstPortion.Style); secondPortion.Style.FontName = FontSettings.GetAdobeFontName("Arial"); textLayer.TextData.AddPortion(secondPortion); textLayer.TextData.UpdateLayerData(); image.Save(outputFilePng, new PngOptions()); image.Save(outputFilePsd); } using (var image = (PsdImage)Image.Load(outputFilePsd)) { TextLayer textLayer = (TextLayer)image.Layers[2]; string adobeFontName1 = FontSettings.GetAdobeFontName("Comic Sans MS"); string adobeFontName2 = FontSettings.GetAdobeFontName("Arial"); AssertAreEqual(adobeFontName1, textLayer.TextData.Items[0].Style.FontName); AssertAreEqual(adobeFontName2, textLayer.TextData.Items[1].Style.FontName); } //ExEnd:SupportOfEditFontNameInTextPortionStyle Console.WriteLine("SupportOfEditFontNameInTextPortionStyle executed successfully"); File.Delete(outputFilePng); File.Delete(outputFilePsd); }