C#を使用してPSD画像をラスタ形式に変換する
概要
Aspose.PSDを使用すると、PSDおよびPSB形式をJPEG、JPEG2000、PNG、TIFF、PDF、GIF、BMP形式に変換できます。
Photoshopを使用せずにサーバーでPSDファイルを変換できます。Adobe Photoshopのスクリプティングの代替手段として、AdobeのEULAはサーバーでアプリを使用してUIを変更することを禁止しています。しかし、PSD Format SDKを使用すると、PSDファイルのバッチ変換が可能です。PSD形式のエクスポートは読み取り専用モードを使用してピクセル完全にできます。または、レイヤー、テキスト、エフェクトを変更してからエクスポートすることもできます。
PSDをラスタ形式にエクスポートする具体的な例
PSD画像をさまざまなラスタファイル形式にエクスポート
以下に示すサンプルコードは、PSDを複数のラスタファイル形式に変換する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string srcPath = dataDir + @"sample.psd"; | |
string destName = dataDir + @"export"; | |
// Load an existing PSD image as Image | |
using (Image image = Image.Load(srcPath)) | |
{ | |
// Create an instance of PngOptions class | |
PngOptions pngOptions = new PngOptions(); | |
// Create an instance of BmpOptions class | |
BmpOptions bmpOptions = new BmpOptions(); | |
// Create an instance of TiffOptions class | |
TiffOptions tiffOptions = new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.Default); | |
// Create an instance of GifOptions class | |
GifOptions gifOptions = new GifOptions(); | |
// Create an instance of JpegOptions class | |
JpegOptions jpegOptions = new JpegOptions(); | |
// Create an instance of Jpeg2000Options class | |
Jpeg2000Options jpeg2000Options = new Jpeg2000Options(); | |
// Call the save method, provide output path and export options to convert PSD file to various raster file formats. | |
image.Save(destName + ".png", pngOptions); | |
image.Save(destName + ".bmp", bmpOptions); | |
image.Save(destName + ".tiff", tiffOptions); | |
image.Save(destName + ".gif", gifOptions); | |
image.Save(destName + ".jpeg", jpegOptions); | |
image.Save(destName + ".jp2", jpeg2000Options); | |
} |