资源预览内容
第1页 / 共16页
第2页 / 共16页
第3页 / 共16页
第4页 / 共16页
第5页 / 共16页
第6页 / 共16页
第7页 / 共16页
第8页 / 共16页
第9页 / 共16页
第10页 / 共16页
亲,该文档总共16页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
LeadTools 中文图像处理教程( 9):添加图像至另一个图像 在图像处理过程中,在很多场景下我们都需要将一个图像添加至另一个图像中,即合并图像, LeadTools 在合并图像方面为您提供了多种方式,如将一个图像覆盖在另一个图像的一部分上,将两个图像以固定的不透明度合并,合并图像并使一个图像看起来像另一个图像的底纹等等。 下面,赶快跟随我们的博文了解 LeadTools 合并图像的相关类、方法和创建程序的具体步骤吧! 本文主要包括: 1 创建“将一个图像添加至另一图像”应用程序的具体步骤 2 LeadTools“添加图像”的相关类和方法 3 简介 get 和 put 像素数据的高级 /低级方法和类 创建“将一个图像添加至另一图像”应用程序的具体步骤 1. 打开 Visual Studio .NET。点击 文件 -新建 -项目 。打开新建项目对话框后,在模板中选择“ Visual C#”或“ Visual Basic”,随后选择“ Windows窗体应用程序 ”。在名称栏中输入项目名称“ AddImage”,并使用“浏览”按钮选择您工程的存储路径,点击“确定”。 2. 在“解决方案资源管理器”中,右击“引用”,选择“添加引用”。 根据当前工程的 Framework 版本和生成目标平台,选择添加相应的 LeadTools控件,例如工程中的版本为 Framework 4.0、生成目标平台是 x86,则浏览选择Leadtools For .NET 文 件 夹 ” BinDotNet4Win32” ,选择以下的 DLL“: Leadtools.dll Leadtools.Codecs.dll Leadtools.Codecs.Cmp.dll Leadtools.Codecs.Bmp.dll Leadtools.ImageProcessing.Core.dll Leadtools.ImageProcessing.Effects.dll Leadtools.ImageProcessing.SpecialEffects.dll Leadtools.WinForms.dll 3. 从 工具箱 (视图 -工具箱),添加 10 个 RadioButton 控件 (将 RadioButton的 Text 属性依照下表修改),两个 Panel 控件 ( Name 分别修改为 panelBefore和 panelAfter)。如下图: Name Text radioButton1 使用 CombineCommand 合并图像 radioButton2 使用 CombineWarpCommand 合并图像 radioButton3 使用 Underlay 合并图像 radioButton4 使用 PicturizeListCommand 合并图像 radioButton5 使用 PicturizeSingleCommand 合并图像 radioButton6 使用 AlphaBlendCommand 合并图像 radioButton7 使用 FeatherAlphaBlendCommand 合并图像 radioButton8 使用 BumpMapCommand 合并图像 radioButton9 使用 TextureAlphaBlendCommand 处理图像 radioButton10 使用 DigitalSubtractCommand 合并图像 4. 切换至 Form1 的代码视图(右击 Form1,选择查看代码),将下面几行代码添加到文件开始处: 1: using Leadtools; 2: using Leadtools.WinForms; 3: using Leadtools.Codecs; 4: using Leadtools.Codecs.Cmp; 5: using Leadtools.Codecs.Bmp; 6: using Leadtools.ImageProcessing; 7: using Leadtools.ImageProcessing.Core; 8: using Leadtools.ImageProcessing.Effects; 9: 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 RasterImageViewer(); 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, .Piccannon.jpg); 7. 双击 radioButton1,在 radioButton1 CheckedChanged 事件句柄中添加以下代码:(本段代码为 CombineCommand 类 的使用) 1: temp = beforePic.Image.Clone(); 2: 3: CombineCommand command = new CombineCommand(); 4: command.SourceImage = temp.Clone(); 5: command.DestinationRectangle = new LeadRect(temp.Width / 8, temp.Height / 8, temp.Width, temp.Height); 6: command.SourcePoint = new LeadPoint(0, 0); 7: command.Flags = CombineCommandFlags.OperationAdd | CombineCommandFlags.Destination0 | CombineCommandFlags.SourceRed | CombineCommandFlags.DestinationGreen | CombineCommandFlags.ResultBlue; 8: command.Run(temp); 9: afterPic.Image = temp; 8. 双击 radioButton2,在 radioButton2 CheckedChanged 事件句柄中添加以下代码(本段代码为 CombineWarpCommand 类 的使用): 1: RasterImage parentImage = beforePic.Image.Clone(); 2: RasterImage childImage = codecs.Load(Path.Combine(Application.StartupPath, .PicImage1.jpg); 3: / 合并图像 4: CombineWarpCommand command = new CombineWarpCommand(); 5: 6: LeadPoint destPoints = 7: 8: new LeadPoint(100,100), 9: new LeadPoint(200,75), 10: new LeadPoint(200,200), 11: new LeadPoint(100,200) 12: ; 13: 14: command.DestinationImage = parentImage; 15: command.SetDestinationPoints(destPoints); 16: command.SourceRectangle = new LeadRect(0, 0, childImage.Width, childImage.Height); 17: command.Flags = CombineWarpCommandFlags.Bilinear; 18: command.Run(childImage); 19: / 保存至磁盘 20: codecs.Save(parentImage, Path.Combine(Application.StartupPath, .PicCombineWarpCommand.bmp), RasterImageFormat.Bmp, 24); 21: afterPic.Image = parentImage; 8. 双击 radioButton3,在 radioButton3 CheckedChanged 事件句柄中添加以下代码(本段代码为 Underlay 类 的使用): 1: RasterImage image = beforePic.Image.Clone(); 2: / 加载底层的图像 3: RasterImage underlayImage = codecs.Load(Path.Combine(Application.StartupPath, .PicImage1.jpg); 4: / 使用 underlayImage作为图像平铺的衬底 5
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号