彩票走势图

ImageGear for .NET使用教程:为控制台应用程序配置C#或VB.NET项目(上)

原创|使用教程|编辑:status|2020-04-03 15:05:09.583|阅读 396 次

概述:ImageGear for .NET使用教程

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

ImageGear for .NET是一款图形图像处理控件,具有扫描,压缩,浏览、添加注释,打印,图像编辑,OCR以及PDF和矢量图像支持,使开发人员可以快速地开发出图像处理程序,可用于.NET Framework2.0、3.0、3.5、4.0,ASP.NET,WPF,SilverLight,DirectX 10和Direct3D 10。支持超过100种图片格式,包含:TIFF, JPEG, CAD, Vector, 3D PDF, PDF/A, PS等。

点击下载ImageGear for .NET正式版

在本教程中,您将为控制台应用程序配置C#或VB.NET项目,并使用ImageGear .NET功能。 您还将学习如何加载图像,然后调整大小并将其转换为新格式。

以下教程专门针对64位安装。 对于32位安装:

  • 您的项目应该已经设置为可编译为以Debug和x86为目标,并且您应该具有以下目录:$ YOURLOCALPROJ \ bin \ x86 \ Debug \。
  • 在整个说明中,将x64替换为x86。
  • 在$ INSTALLDIR \ ImageGear .NET v24 \ Bin \中可以找到32位ImageGear二进制文件。

使用所需版本的Visual Studio(2010或更高版本):

1、使用C#或VB.NET创建一个新的“控制台应用程序”项目,并将该项目命名为IG_Tutorial_Console

2、如果使用配置管理器安装了ImageGear .NET 64位,则为x64创建一个新的项目平台(如果尚未安装)。确保将项目设置为针对Debug和x64进行编译。确保您现在拥有$ YOURLOCALPROJ \ bin \ x64 \ Debug \,如果不存在,请创建它。

3、通过以下方式之一将引用和所需资源添加到项目中:
推荐:使用我们的NuGet软件包。对于此项目,您需要以下软件包:Accusoft.ImageGear.Core.nupkg

手动:

将$ INSTALLDIR \ ImageGear .NET v24 64位\ Bin \中的所有文件(和文件夹)复制到项目中的本地输出bin目录(即$ YOURLOCALPROJ \ bin \ x64 \ Debug \)。

将以下引用从$ YOURLOCALPROJ \ bin \ x64 \ Debug \添加到您的项目:

  • ImageGear24.Core.dll
  • ImageGear24.Evaluation.dll
  • ImageGear24.Formats.Common.dll
您的输出目标目录应设置为$ YOURLOCALPROJ \ bin \ x64 \ Debug \

4、至此,您的项目已准备好编写一些代码。以下代码可用于加载图像,将其调整为150 x 150尺寸,并将其转换为用户指定的另一种格式。在下一步中,我们将更详细地介绍此示例代码的某些区域。

C#

using System;
using System.IO;

using ImageGear.Core;
using ImageGear.Evaluation;
using ImageGear.Formats;
using ImageGear.Processing;
using ImageGear.Display;

namespace IG_Tutorial_Console
{
   class Program
   {
static void Main(string[] args)
{
// Initialize license for a Deployment(Runtime) license.
//***The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey
//methods must be called to distribute the runtime.***
//ImGearLicense.SetSolutionName("YourSolutionName");
//ImGearLicense.SetSolutionKey(12345, 12345, 12345, 12345);
//Manually Reported Runtime licenses also require the following method
//call to SetOEMLicenseKey.
//ImGearLicense.SetOEMLicenseKey("2.0.AStringForOEMLicensing...");

// Initialize evaluation license.
ImGearEvaluationManager.Initialize();

// Initialize common formats.
ImGearCommonFormats.Initialize();

Console.WriteLine("Enter the complete path to the image to be converted:");
string fileName = Console.ReadLine();

Console.WriteLine("Enter the format for the new image among BMP|GIF|JPG|PNG|TIFF:");
string newFormat = Console.ReadLine();

try
   {   
    using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
    {
 try
 {

 // Load the image into the page.
 ImGearPage imGearPage = ImGearFileFormats.LoadPage(stream, 0);

 // Resize the image to the width and height specified.
 // ImGearInterpolations.BILINEAR is the value indicating the type of interpolation employed.
 // It may be changed for other values, e.g. ImGearInterpolations.BICUBIC, ImGearInterpolations.NEAREST_NEIGHBOR.
 ImGearProcessing.Resize(imGearPage, 150, 150, ImGearInterpolationOptions.GetDefault(ImGearInterpolations.BILINEAR));

 string outputFileName = fileName.Substring(0,fileName.LastIndexOf('\\') + 1) + "out.";

 // Indicate the format used when saving the image.
 // It may be changed for other values, e.g. ImGearSavingFormats.JPG, ImGearSavingFormats.PNG.
 ImGearSavingFormats savingFormat = ImGearSavingFormats.UNKNOWN;

 // Identify the format selected.
 switch (newFormat)
 {

     case "BMP":
  outputFileName += "bmp";
  savingFormat = ImGearSavingFormats.BMP_UNCOMP;
  break;
     case "GIF":
  outputFileName += "gif";
  savingFormat = ImGearSavingFormats.GIF;
  break;
     case "JPG":
  outputFileName += "jpg";
  savingFormat = ImGearSavingFormats.JPG;
  break;      
     case "PNG":
  outputFileName += "png";
  savingFormat = ImGearSavingFormats.PNG;
  break;   
     case "TIFF":
  outputFileName += "tiff";
  savingFormat = ImGearSavingFormats.TIF_UNCOMP;
  break;
     default:
  Console.WriteLine("Unsupported format.");
  break;
 }  

 if (savingFormat != ImGearSavingFormats.UNKNOWN)
 {
     using (FileStream imGearConverted = new FileStream(outputFileName, FileMode.Create))
     {
  // Save the image to the format selected.   
  ImGearFileFormats.SavePage(imGearPage, imGearConverted, 1, ImGearSavingModes.OVERWRITE, savingFormat, new ImGearSaveOptions());
     }

     Console.WriteLine("Conversion successful.");
 }

 }
 catch (ImGearException ex)
 {
 Console.WriteLine("Conversion failed: " + ex.Message);
 }
    }
   }
   catch (Exception)
   {
    Console.WriteLine("Incorrect path to an image file.");
   }
Console.ReadLine();

}

   }
}

VB.NET

 Imports System
Imports System.IO

Imports ImageGear.Core
Imports ImageGear.Evaluation
Imports ImageGear.Formats
Imports ImageGear.Processing
Imports ImageGear.Display

Module Module1

   Sub Main()
' Initialize license for a Deployment(Runtime) license.
'***The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey
'methods must be called to distribute the runtime.***
'ImGearLicense.SetSolutionName("YourSolutionName");
'ImGearLicense.SetSolutionKey(12345, 12345, 12345, 12345);
'Manually Reported Runtime licenses also require the following method
'call to SetOEMLicenseKey.
'ImGearLicense.SetOEMLicenseKey("2.0.AStringForOEMLicensing...");

'Initialize evaluation license.
ImGearEvaluationManager.Initialize()

'Initialize common formats.
ImGearCommonFormats.Initialize()

Console.WriteLine("Enter the complete path to the image to be converted:")
Dim fileName As String = Console.ReadLine()

Console.WriteLine("Enter the format for the new image among BMP|GIF|JPG|PNG|TIFF:")
Dim newFormat As String = Console.ReadLine()

Try
Using stream As New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)
    Try
 ' Load the image into the page.
 Dim imGearPage As ImGearPage = ImGearFileFormats.LoadPage(stream, 0)

 ' Resize the image to the width and height specified.
 ' ImGearInterpolations.BILINEAR is the value indicating the type of interpolation employed.
 ' It may be changed for other values, e.g. ImGearInterpolations.BICUBIC, ImGearInterpolations.NEAREST_NEIGHBOR.
 ImGearProcessing.Resize(imGearPage, 150, 150, ImGearInterpolationOptions.GetDefault(ImGearInterpolations.BILINEAR))

 Dim outputFileName As String = fileName.Substring(0, fileName.LastIndexOf("\") + 1) + "out."

 ' Indicate the format used when saving the image.
 ' It may be changed for other values, e.g. ImGearSavingFormats.JPG, ImGearSavingFormats.PNG.
 Dim savingFormat As ImGearSavingFormats = ImGearSavingFormats.UNKNOWN

 ' Identify the format selected.

 S elect Case newFormat
 Case "BMP"
     outputFileName += "bmp"
     savingFormat = ImGearSavingFormats.BMP_UNCOMP
 Case "GIF"
     outputFileName += "gif"
     savingFormat = ImGearSavingFormats.GIF
 Case "JPG"
     outputFileName += "jpg"
     savingFormat = ImGearSavingFormats.JPG
 Case "PNG"
     outputFileName += "png"
     savingFormat = ImGearSavingFormats.PNG
 Case "TIFF"
     outputFileName += "tiff"
     savingFormat = ImGearSavingFormats.TIF_UNCOMP
 End S elect

 If Not savingFormat = ImGearSavingFormats.UNKNOWN Then
 Using imGearConverted As FileStream = New FileStream(outputFileName, FileMode.Create)
     ' Save the image to the format selected.   
     ImGearFileFormats.SavePage(imGearPage, imGearConverted, 1, ImGearSavingModes.OVERWRITE, savingFormat, New ImGearSaveOptions())
     Console.WriteLine("Conversion successful.")
 End Using
 Else
 Console.WriteLine("Unsupported format.")
 End If

    Catch ex As Exception
 Console.WriteLine("Conversion failed: " + ex.Message)
    End Try

End Using

Catch ex As Exception
Console.WriteLine("Incorrect path to an image file.")
End Try

Console.ReadLine()

   End Sub

End Module

想要购买ImageGear for .NET正版授权,或了解更多产品信息请点击


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP