原創(chuàng)|使用教程|編輯:status|2020-04-03 15:05:09.583|閱讀 455 次
概述:ImageGear for .NET使用教程
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
ImageGear for .NET是一款圖形圖像處理控件,具有掃描,壓縮,瀏覽、添加注釋,打印,圖像編輯,OCR以及PDF和矢量圖像支持,使開發(fā)人員可以快速地開發(fā)出圖像處理程序,可用于.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等。
點(diǎn)擊下載ImageGear for .NET正式版
在本教程中,您將為控制臺應(yīng)用程序配置C#或VB.NET項(xiàng)目,并使用ImageGear .NET功能。 您還將學(xué)習(xí)如何加載圖像,然后調(diào)整大小并將其轉(zhuǎn)換為新格式。
以下教程專門針對64位安裝。 對于32位安裝:
使用所需版本的Visual Studio(2010或更高版本):
1、使用C#或VB.NET創(chuàng)建一個新的“控制臺應(yīng)用程序”項(xiàng)目,并將該項(xiàng)目命名為IG_Tutorial_Console。
2、如果使用配置管理器安裝了ImageGear .NET 64位,則為x64創(chuàng)建一個新的項(xiàng)目平臺(如果尚未安裝)。確保將項(xiàng)目設(shè)置為針對Debug和x64進(jìn)行編譯。確保您現(xiàn)在擁有$ YOURLOCALPROJ \ bin \ x64 \ Debug \,如果不存在,請創(chuàng)建它。
3、通過以下方式之一將引用和所需資源添加到項(xiàng)目中:
推薦:使用我們的NuGet軟件包。對于此項(xiàng)目,您需要以下軟件包:Accusoft.ImageGear.Core.nupkg
手動:
將$ INSTALLDIR \ ImageGear .NET v24 64位\ Bin \中的所有文件(和文件夾)復(fù)制到項(xiàng)目中的本地輸出bin目錄(即$ YOURLOCALPROJ \ bin \ x64 \ Debug \)。
將以下引用從$ YOURLOCALPROJ \ bin \ x64 \ Debug \添加到您的項(xiàng)目:
4、至此,您的項(xiàng)目已準(zhǔn)備好編寫一些代碼。以下代碼可用于加載圖像,將其調(diào)整為150 x 150尺寸,并將其轉(zhuǎn)換為用戶指定的另一種格式。在下一步中,我們將更詳細(xì)地介紹此示例代碼的某些區(qū)域。
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
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn