翻譯|使用教程|編輯:李顯亮|2020-12-21 10:40:08.310|閱讀 1004 次
概述:將PSD圖像直接查看或嵌入到Web或桌面應用程序中是不可行的。為了解決此問題,您可以將PSD文檔轉換為PDF或光柵圖像格式。本文提供了一些使用Java將PSD文件轉換為PDF,PNG,JPEG,GIF和其他圖像格式的簡單方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PSD格式由Adobe Photoshop使用,以保存與圖形設計有關的數據。PSD文件可以由集體形成圖形的單個或多個圖層組成。但是,將PSD圖像直接查看或嵌入到Web或桌面應用程序中是不可行的。
為了解決此問題,可以將PSD文檔轉換為PDF或光柵圖像格式。因此,本文提供了一些使用Java將PSD文件轉換為PDF,PNG,JPEG,GIF和其他圖像格式的簡單方法。
Aspose.PSD for Java是功能強大的PSD文件操作API,可讓您從Java應用程序中處理,編輯和轉換PSD文檔。API的轉換器引擎使您可以將PSD文件轉換為高保真度的其他格式。如果你還沒有用過Aspose.PSD可以點擊這里下載最新版測試。
PDF是最受歡迎的數字文檔格式之一,無論硬件或軟件如何,PDF均可確保文檔布局的穩定性。因此,在大多數情況下都可以采用PSD到PDF的轉換。以下是將PSD文件轉換為PDF的步驟。
以下代碼示例顯示了如何在Java中將PSD文件轉換為PDF。
// Load image Image img = Image.load("sample.psd"); // Create PDF options PdfOptions options = new PdfOptions(); // Convert PSD to PDF img.save("psd-to-pdf.pdf", options );
如果不適合將PSD轉換為PDF,則可以選擇其他選項。PSD轉換為光柵圖像。以下是將PSD文件轉換為特定柵格圖像格式的步驟。
下面的代碼示例演示如何使用Java將PSD文件轉換為PNG,JPEG,BMP,GIF和JPEG 2000圖像。
// Load an existing PSD image as Image Image image = Image.load("sample.psd"); // Create an instance of PngOptions class PngOptions pngOptions = new PngOptions(); // Create an instance of BmpOptions class BmpOptions bmpOptions = new BmpOptions(); // 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("psd-to-png.png", pngOptions); image.save("psd-to-bmp.bmp", bmpOptions); image.save("psd-to-gif.gif", gifOptions); image.save("psd-to-jpg.jpeg", jpegOptions); image.save("psd-to-jp2.jp2", jpeg2000Options);
還可以將PSD文件中的特定圖層轉換為柵格圖像。下面的代碼示例演示如何將PSD文件中的每一層轉換為單獨的PNG圖像。
// Load a PSD file as an image and caste it into PsdImage PsdImage psdImage = (PsdImage) Image.load("sample.psd"); // Create an instance of PngOptions class PngOptions pngOptions = new PngOptions(); pngOptions.setColorType(PngColorType.TruecolorWithAlpha); // Loop through the list of layers for (int i = 0; i < psdImage.getLayers().length; i++) { // Convert and save the layer to PNG file format. psdImage.getLayers()[i].save(String.format("layer_out{0}.png", i + 1), pngOptions); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn