使用Visual Studio处理图像

按照以下步骤创建并运行一个程序,将图像添加到Visual Studio中的LEADTOOLS ImageViewer对象。

  1. 启动Visual Studio。
  2. 选择文件- >- >项目…菜单上的。
  3. 在“新建项目”对话框中,选择“项目类型——>Visual c#项目——>NET Framework 4.0”。然后选择“WPF App(。净框架)”。
  4. 输入项目名称为“ImageViewerItems“在项目名称字段,然后单击好吧.类型为项目键入新位置或选择目录(如果需要)浏览按钮,然后单击好吧
  5. 在“解决方案资源管理器窗口中,右键单击参考文献"文件夹并选择"添加引用…从上下文菜单。在“添加引用…对话框中,选择浏览"标签并浏览到。net的领先技术"C: \ LEADTOOLS22 \ Bin \ DotNet4 \ Win32文件夹,然后选择以下dll:

    • Leadtools.dll
    • Leadtools.Codecs.dll
    • Leadtools.Controls.Wpf.dll点击选择然后点击好吧将上述dll添加到应用程序。
  6. MainWindow.xaml到水平拆分,以便查看XAML代码。的源代码中插入XAML代码片段MainWindow.xaml.所提供的源代码旨在用Visual Studio和Expression Blend构建应用程序。

  7. 显示图像。加载图像只需要向源代码中添加以下XAML代码。确保您删除了默认加载到窗口中的任何源代码。
    MainWindow.xaml
    <窗口xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x = " http://schemas.microsoft.com/winfx/2006/xaml "x: Class = " ImageViewerItems。主窗口”x: Name = "窗口"Title =“ImageViewerItems”宽度= " 640 "身高= " 480 "xmlns: Leadtools_Controls_Wpf = " clr-namespace: Leadtools.Controls;装配= Leadtools.Controls.Wpf”><网格x: Name = " LayoutRoot "><Leadtools_Controls_Wpf:ImageViewer x:Name="_imageList" Margin="124,132,205,124" Loaded="ImageViewer_Loaded"/></网格></窗口>
  8. 打开文件后面的代码MainWindow.xaml.cs,删除该文件中的默认代码,并将其全部替换为以下代码。

    MainWindow.xaml.cs
    使用先;使用System.Windows;使用Leadtools;使用Leadtools.Codecs;使用Leadtools.Controls;名称空间ImageViewerItems///<摘要>///xaml的交互逻辑///> < /总结公共部分MainWindow:窗口公共主窗口()InitializeComponent ();静态LEAD_VARS公共常量字符串ImagesDir =@“C: \ LEADTOOLS22 \ Resources \图片”私人无效ImageViewer_Loaded (对象发送者,RoutedEventArgs_imageList.Zoom (ControlSizeMode。拉伸,1.0,_imageList.DefaultZoomOrigin);使用(RasterCodecs codecs =RasterCodecs ())字符串srcFileName = Path.Combine(LEAD_VARS.ImagesDir,@“ImageProcessingDemo \ NaturalFruits.jpg”);RasterImage image = codecs.Load(srcFileName);_imageList。Image =图像;

  9. 构建并运行程序以测试它。

  10. 放大镜。访问放大镜需要粘贴以下XAML代码。确保从文件中删除任何其他代码。

    MainWindow.xaml
    <窗口xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x = " http://schemas.microsoft.com/winfx/2006/xaml "x: Class = " ImageViewerItems。主窗口”x: Name = "窗口"Title =“ImageViewerItems”宽度= " 640 "身高= " 480 "xmlns: Leadtools_Controls_Wpf = " clr-namespace: Leadtools.Controls;装配= Leadtools.Controls.Wpf”><网格x: Name = " LayoutRoot "><Leadtools_Controls_Wpf:ImageViewer x:Name="_imageList" Margin="124,132,205,124" Loaded="ImageViewer_Loaded"><Leadtools_Controls_Wpf: imageview。InteractiveModes><Leadtools_Controls_Wpf:ImageViewerMagnifyGlassInteractiveMode Shape="Rectangle" ScaleFactor="3" IsEnabled="True"/></ Leadtools_Controls_Wpf: imageview。InteractiveModes></ Leadtools_Controls_Wpf: imageview></网格></窗口>

  11. 构建并运行程序以测试它。

  12. 具有多个项目的图像查看器。要将多个项目添加到图像查看器控件中,使其看起来像缩略图图像列表,请将XAML文件的内容和文件后面的代码替换为如下所示。确保从源文件中删除了任何其他源代码。
    MainWindow.xaml
    <窗口xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x = " http://schemas.microsoft.com/winfx/2006/xaml "x: Class = " ImageViewerItems。主窗口”x: Name = "窗口"Title =“ImageViewerItems”宽度= " 640 "身高= " 480 "xmlns: Leadtools_Controls_Wpf = " clr-namespace: Leadtools.Controls;装配= Leadtools.Controls.Wpf”><网格x: Name = " LayoutRoot "><Leadtools_Controls_Wpf:ImageViewer x:Name="_imageList" viewhorizontalalign ="Center" viewverticalalign ="Center" ItemSpacing="10,10" ItemSize="150,150" ItemBorderThickness="1" Loaded="ImageViewer_Loaded"><Leadtools_Controls_Wpf: imageview。ViewLayout><= " 1 " / Leadtools_Controls_Wpf: ImageViewerVerticalViewLayout列></ Leadtools_Controls_Wpf: imageview。ViewLayout><Leadtools_Controls_Wpf: imageview。InteractiveModes><Leadtools_Controls_Wpf:ImageViewerMagnifyGlassInteractiveMode Shape="Rectangle" ScaleFactor="3" IsEnabled="True"/></ Leadtools_Controls_Wpf: imageview。InteractiveModes></ Leadtools_Controls_Wpf: imageview></网格></窗口>
    MainWindow.xaml.cs
    使用先;使用System.Windows;使用Leadtools;使用Leadtools.Codecs;使用Leadtools.Controls;名称空间ImageViewerItems///<摘要>///xaml的交互逻辑///> < /总结公共部分MainWindow:窗口公共主窗口()InitializeComponent ();LeadSize _imageSize = LeadSize。创建(130、130);私人无效ImageViewer_Loaded (对象发送者,RoutedEventArgsAddItem (Path.Combine (LEAD_VARS.ImagesDir@“ImageProcessingDemo \ NaturalFruits.jpg”));AddItem (Path.Combine (LEAD_VARS.ImagesDir@“ImageProcessingDemo \ Ani.gif”));AddItem (Path.Combine (LEAD_VARS.ImagesDir@“ImageProcessingDemo \ Image2.jpg”));私人无效AddItem (字符串文件名)使用(RasterCodecs codecs =RasterCodecs ())_imageList.BeginUpdate ();RasterImage = codecs.Load(fileName);LeadRect destRect = LeadRect。创建(0,0,_imageSize.)宽度,_imageSize.Height);LeadRect imag勃起= ImageViewer。GetDestinationRectangle (rasterImage。ImageWidth,rasterImage。ImageHeight,destRect,ControlSizeMode。健康,ControlAlignment。附近,ControlAlignment.Near);RasterImage缩略图= RasterImage。CreateThumbnail (imageRect。宽度,imageRect。高度,32岁的RasterViewPerspective。TopLeft,RasterSizeFlags.Resample);ImageViewerItem item =ImageViewerItem ();项。图片=缩略图;_imageList.Items.Add(项);_imageList.EndUpdate ();静态LEAD_VARS公共常量字符串ImagesDir =@“C: \ LEADTOOLS22 \ Resources \图片”
  13. 构建并运行程序以测试它。

编程参考

LEADTOOLS成像、医疗和文档
188金宝搏的网址客服|支持|联系我们|知识产权公告
©1991 - 2023领德科技有限公司版权所有。