このステップバイステップのチュートリアルでは、C#でEPSをTIFFに変換する方法を説明します。 EPSファイルは、図面を含むAdobeのカプセル化されたPostScript形式です。 Aspose.Page for .NETを使用すると、いくつかの手順でEPSをC#コードのTIFFに変換できます。
C#でEPSをTIFFに変換する手順
- NuGet.orgからAspose.Page for .NETパッケージをインストールします
- Aspose.Page、Aspose.Page.EPS、およびAspose.Page.EPS.Device名前空間を含める
- SetLicenseメソッドを使用してAPIライセンスを適用します
- EPSファイルをPsDocument objectにロードします
- TIFF画像形式を使用してImageDeviceオブジェクトを作成します
- 必要に応じてImageSaveOptionsを設定します
- EPSドキュメントを上で作成したTIFF画像デバイスに保存します
- 画像デバイスからバイト配列を読み取り、tiff画像として保存します
上記の手順から、PsDocumentオブジェクトがEPSドキュメントを画像バイトとしてTIFF画像デバイスにレンダリングすることがわかります。この画像デバイスは、後でそれらの画像バイトをTIFF画像としてレンダリングするのに役立ちます。
C#でEPSをTIFFに変換するコード
using System; | |
using System.IO; | |
using System.Drawing.Imaging; | |
//Add reference to Aspose.Page for .NET API | |
//Use following namespace to convert EPS to TIFF file type | |
using Aspose.Page; | |
using Aspose.Page.EPS; | |
using Aspose.Page.EPS.Device; | |
namespace ConvertEPSToTIFF | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Set Aspose license before converting EPS to TIFF type | |
//using Aspose.Page for .NET | |
Aspose.Page.License AsposePageLicense = new Aspose.Page.License(); | |
AsposePageLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
FileStream InputEPSFileToBeConverted = File.Open("EPSFileToBeConverted.eps", FileMode.Open, FileAccess.Read); | |
PsDocument InputEPSDocument = new PsDocument(InputEPSFileToBeConverted); | |
ImageDevice TiffImageDevice = new ImageDevice(ImageFormat.Tiff); | |
SaveOptions saveOptions = new ImageSaveOptions(); | |
InputEPSDocument.Save(TiffImageDevice, saveOptions); | |
// Get image bytes array | |
byte[][] TiffImagesBytes = TiffImageDevice.ImagesBytes; | |
//loop through image bytes array and add to tiff file | |
int ImageBytesCount = 0; | |
foreach (byte[] TiffImageBytes in TiffImagesBytes) | |
{ | |
using (FileStream OutputTIFFFileConverted = new FileStream("OutputConvertedTIFFFile.tiff", FileMode.Create, FileAccess.Write)) | |
{ | |
OutputTIFFFileConverted.Write(TiffImageBytes, 0, TiffImageBytes.Length); | |
} | |
ImageBytesCount++; | |
} | |
} | |
} | |
} |
上記のコードスニペットでは、いくつかの手順で、c#コードを使用してTIFFにconvert EPSする方法を理解したことがわかります。このコードを使用すると、Web、デスクトップ、Windows、サービスなど、任意の.NETアプリケーションでEPSからTIFFへのコンバーターを作成できます。