LeadTools创建“艺术效果”应用程序的具体步骤

2025-10-23 09:57:28

1、打开Visual Studio .NET。点击 文件->新建->项目…。打开新建项目对话框后,在模板中选择“Visual C#”或“Visual Basic”,随后选择“Windows窗体应用程序”。在名称栏中输入项目名称“ApplyArtisticEffects”,并使用“浏览”按钮选择您工程的存储路径,点击“确定”。

2、在“解决方案资源管理器”中,右击“引用”,选择“添加引用”。根据当前工程的 Framework 版本和生成目标平台,选择添加相应的LeadTools控件,例如工程中的版本为 Framework 4.0、生成目标平台是 x86,则浏览选择Leadtools For .NET文件夹” <LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32”,选择以下的DLL“:Leadtools.dllLeadtools.Codecs.dllLeadtools.Codecs.Cmp.dllLeadtools.ImageProcessing.Effects.dll Leadtools.ImageProcessing.SpecialEffects.dll Leadtools.WinForms.dll

3、从工具箱(视图->工具箱),添加12个RadioButton控件(将RadioButton的Text属性依照下表修改),两个Panel控件(Name分别修改为panelBefore和panelAfter)。如下图:

LeadTools创建“艺术效果”应用程序的具体步骤

4、切换至Form1的代码视图(右击Form1,选择查看代码),将下面几行代码添加到文件开始处:1: using Leadtools; 2: using Leadtools.Codecs; 3: using Leadtools.WinForms; 4: using Leadtools.ImageProcessing; 5: using Leadtools.ImageProcessing.Effects; 6: using Leadtools.ImageProcessing.SpecialEffects;

5、将以下变量添加至Form1类:1: private RasterImageViewer beforePic; 2: private RasterImageViewer afterPic; 3: private RasterCodecs codecs; 4: private RasterImage temp;

6、添加Form1 Load事件句柄,在其中添加以下代码:1: beforePic = new RasterImageVi髫潋啜缅ewer(); 2: beforePic.BackColor = Color.DarkCyan; 3: beforePic.Dock = DockStyle.Fill; 4: beforePic.InteractiveMode = RasterViewerInteractiveMode.Pan; 5: beforePic.HorizontalAlignMode = RasterPaintAlignMode.Center; 6: beforePic.VerticalAlignMode = RasterPaintAlignMode.Center; 7: beforePic.AutoResetScaleFactor = false; 8: panelBefore.Controls.Add(beforePic); 9: beforePic.BringToFront();10:11: afterPic = new RasterImageViewer();12: afterPic.BackColor = beforePic.BackColor;13: afterPic.Dock = beforePic.Dock;14: afterPic.InteractiveMode = beforePic.InteractiveMode;15: afterPic.HorizontalAlignMode = beforePic.HorizontalAlignMode;16: afterPic.VerticalAlignMode = beforePic.VerticalAlignMode;17: afterPic.AutoResetScaleFactor = beforePic.AutoResetScaleFactor;18: panelAfter.Controls.Add(afterPic);19: afterPic.BringToFront();20:21: codecs = new RasterCodecs();22: codecs.ThrowExceptionsOnInvalidImages = true;23: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\Image.jpg"));

7、双击radioButton1,在radioButton1 CheckedChanged事件句柄中添加以下代码:(本段代码为AddNoiseCommand类的使用)1: temp = beforePic.Image.Clone(); 2: 3: AddNoiseCommand command = new AddNoiseCommand(); 4: command.Range = 250; 5: 6: command.Channel = RasterColorChannel.Red; 7: command.Run(temp); 8: afterPic.Image = temp; 9: codecs.Save(temp, Path.Combine(Application.StartupPath, @"..\..\Pic\AddNoiseCommand.jpg"), RasterImageFormat.Jpeg, 24);10:

8、双击radioButton2,在radioButton2 CheckedChanged事件甜入艺阝句柄中添加以下代码:(本段代码为AgingComm锾攒揉敫and类的使用)1: temp = beforePic.Image.Clone(); 2: // 准备命令 3: AgingCommand command = new AgingCommand(); 4: command.HorizontalScratchCount = 10; 5: command.VerticalScratchCount = 2; 6: command.MaximumScratchLength = 50; 7: command.DustDensity = 2; 8: command.PitsDensity = 5; 9: command.MaximumPitSize = 6;10: command.ScratchColor = new RasterColor(255, 255, 0);11: command.DustColor = new RasterColor(0, 0, 0);12: command.PitsColor = new RasterColor(0, 0, 255);13: command.Flags = AgingCommandFlags.AddVerticalScratch | AgingCommandFlags.AddPits | AgingCommandFlags.ScratchInverse | AgingCommandFlags.PitsColor;14:15: command.Run(temp);16: afterPic.Image = temp;17:

9、双击radioButton3,在radioButton3 CheckedChanged事件句柄中添加以下代码:(本段代码为BendCommand类的使用) 1: temp = beforePic.Image.Clone(); 2: // 准备命令 3: BendCommand command = new BendCommand(); 4: command.Value = 100; 5: 6: command.CenterPoint = new LeadPoint(temp.Width / 2, temp.Height / 2); 7: command.Flags = BendCommandFlags.Repeat | BendCommandFlags.WithoutRotate | BendCommandFlags.Normal; 8: command.Run(temp); 9: afterPic.Image = temp;

10、双击radioButton4,在radioButton4 CheckedChanged事件甜入艺阝句柄中添加以下代码:(本段代码为BricksTextureCommand类的使用)1: temp = beforePic.Image.Clone(); 2: // 准备命令 3: BricksTextureCommand command= new BricksTextureCommand(); 4: command.BricksWidth = 60; 5: command.BricksHeight = 20; 6: command.OffsetX = 0; 7: command.OffsetY = 0; 8: command.EdgeWidth = 3; 9: command.MortarWidth = 4;10: command.ShadeAngle = 315;11: command.RowDifference = 33;12: command.MortarRoughness = 20;13: command.MortarRoughnessEvenness = 0;14: command.BricksRoughness = 10;15: command.BricksRoughnessEvenness = 0;16: command.MortarColor = new RasterColor(0, 0, 0);17: command.Flags = BricksTextureCommandFlags.SmoothedOutEdges | BricksTextureCommandFlags.TransparentMortar;18:19: //在图像上应用砖块纹理20: command.Run(temp);21: afterPic.Image = temp;

11、双击radioButton5,在radioButton5 CheckedChanged事件句柄中添加以下代码:(本段代码为GlowCommand类的使用) 1: temp = beforePic.Image.Clone(); 2: // 准备命令 3: GlowCommand command = new GlowCommand(); 4: command.Dimension = 5; 5: command.Brightness = 3; 6: command.Threshold = 0; 7: // 在图像上应用发光效果 8: command.Run(temp); 9: afterPic.Image = temp;

12、双击radioButton6,在radioButton6 CheckedChanged事件句柄中添加以下代码:(本段代码为DryCommand类的使用)1: temp = beforePic.Image.Clone(); 2: 3: DryCommand command = new DryCommand(); 4: command.Dimension = 5; 5: command.Run(temp); 6: afterPic.Image = temp;

13、双击radioButton7,在radioButton7 CheckedChanged事件句柄中添加以下代码:(本段代码为ImpressionistCommand类的使用) 1: temp = beforePic.Image.Clone(); 2: 3: ImpressionistCommand command = new ImpressionistCommand(); 4: command.HorizontalDimension = 10; 5: command.VerticalDimension = 10; 6: 7: command.Run(temp); 8: afterPic.Image = temp;

14、双击radioButton8,在radioButton8 CheckedChanged事件甜入艺阝句柄中添加以下代码:(本段代码为MosaicTil髫潋啜缅esCommand类的使用) 1: temp = beforePic.Image.Clone(); 2: 3: MosaicTilesCommand command = new MosaicTilesCommand(); 4: command.BorderColor = new RasterColor(0, 0, 0); 5: command.TilesColor = new RasterColor(255, 255, 255); 6: command.TileWidth = 50; 7: command.TileHeight = 50; 8: command.Opacity = 50; 9: command.ShadowThreshold = 50;10: command.ShadowAngle = ShadowCommandAngle.East;11: command.PenWidth = 7;12: command.Flags = MosaicTilesCommandFlags.Cartesian |MosaicTilesCommandFlags.ShadowGray;13: command.Run(temp);14: afterPic.Image = temp;

15、双击radioButton9,在radioButton9 CheckedChanged事件句柄中添加以下代码:(本段代码为OceanCommand类的使用)1: temp = beforePic.Image.Clone(); 2: 3: OceanCommand command = new OceanCommand(); 4: command.Amplitude = 20; 5: command.Frequency = 6; 6: command.LowerTransparency = true; 7: command.Run(temp); 8: afterPic.Image = temp;

16、双击radioButton10,在radioButton10 CheckedChanged事件句柄中添加以下代码:(本段代码为PlaneBendCommand类的使用)1: temp 租涫疼迟= beforePic.Image.Clone(); 2: 3: PlaneBendCommand command = new PlaneBendCommand(); 4: command.CenterPoint = new LeadPoint(temp.Width / 2, temp.Height / 2); 5: command.ZValue = 0; 6: command.Distance = temp.Height; 7: command.PlaneOffset = temp.Width / 2; 8: command.Repeat = -1; 9: command.PyramidAngle = 0;10: command.Stretch = 100;11: command.BendFactor = 400;12: command.StartBright = 0;13: command.EndBright = 100;14: command.BrightLength = 20000;15: command.BrightColor = new RasterColor(255, 255, 255);16: command.FillColor = new RasterColor(0, 0, 0);17: command.Flags = PlaneCommandFlags.Down | PlaneCommandFlags.Up | PlaneCommandFlags.Color;18: command.Run(temp);19: afterPic.Image = temp;

17、双击radioButton11,在radioButton11 CheckedChanged事件句柄中添加以下代码:(本段代码为RevEffectCommand类的使用)1: temp = beforePic.Image.Clone(); 2: 3: RevEffectCommand command = new RevEffectCommand(); 4: command.LineSpace = 3; 5: command.MaximumHeight = 35; 6: 7: command.Run(temp); 8: afterPic.Image = temp;

18、双击radioButton12,在radioButton12 CheckedChanged事件句柄中添加以下代码:(本段代码为ColoredPencilExtendedCommand类的使用)1: temp = beforePic.Image.Clone(); 2: 3: ColoredPencilExtendedCommand command = new ColoredPencilExtendedCommand(); 4: command.Size = 5; 5: command.Strength = 4; 6: command.Threshold = 0; 7: command.PencilRoughness = 250; 8: command.StrokeLength = 15; 9: command.PaperRoughness = 100;10: command.Flags = ColoredPencilExtendedCommandFlags.Artistic;11: command.Run(temp);12: afterPic.Image = temp;

19、编译运行程序,本DEMO分别使用了12个类处理图像,对图像应用艺术效果,结果如下图:

LeadTools创建“艺术效果”应用程序的具体步骤LeadTools创建“艺术效果”应用程序的具体步骤
猜你喜欢