이 단계별 자습서에서는 C#에서 EPS를 TIFF로 변환하는 방법을 설명합니다. EPS 파일은 그림이 포함된 Adobe의 Encapsulated PostScript 형식입니다. .NET용 Aspose.Page를 사용하면 몇 단계만 거치면 C# 코드에서 EPS를 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 설정
- 위에서 생성한 TIFF 이미지 장치에 EPS 문서를 저장합니다.
- 이미지 장치에서 바이트 배열을 읽고 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하는 방법을 이해했음을 알 수 있습니다. 이 코드를 사용하면 웹, 데스크탑, Windows, 서비스 등을 포함한 모든 .NET 응용 프로그램에서 EPS를 TIFF로 변환하는 변환기를 만들 수 있습니다.