翻譯|行業(yè)資訊|編輯:胡濤|2023-10-26 10:41:09.377|閱讀 113 次
概述:在這篇博文中,我們將討論如何用 Java 創(chuàng)建 PSD 縮略圖,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
PSD文件是一種流行的存儲分層圖像的格式,例如在 Adobe Photoshop 中創(chuàng)建的圖像。然而,PSD 文件可能很大且笨重,使得它們難以在線共享或查看。解決此問題的一種方法是創(chuàng)建 PSD 文件的縮略圖。縮略圖是圖像的較小、分辨率較低的版本,可用于表示原始文件。在這篇博文中,我們將討論如何用 Java 創(chuàng)建 PSD 縮略圖。
Aspose.PSD 是高級PSD文件格式操作API,沒有任何Adobe Photoshop依賴項。API允許創(chuàng)建或編輯Photoshop文件,并提供更新圖層屬性,添加水印,執(zhí)行圖形操作或?qū)⒁环N文件格式轉(zhuǎn)換為另一種文件的功能。支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
我們將使用Aspose.PSD for Java API 來創(chuàng)建 PSD 縮略圖。它是一個功能強大的 API,允許您創(chuàng)建、讀取、編輯和轉(zhuǎn)換 PSD 和PSB文件,而無需 Adobe Photoshop。它是一個綜合性庫,提供了廣泛的功能,包括訪問和修改圖層屬性、添加和刪除圖層、對圖層應(yīng)用效果、將 PSD 文件導(dǎo)出為其他圖像格式、將 PSD 文件渲染為 PDF 等。Aspose.PSD for Java 易于使用并且可以集成到任何 Java 應(yīng)用程序中。
請下載API的JAR或在基于Maven的Java應(yīng)用程序中添加以下pom.xml配置。
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>//repository.aspose.com/repo/</url> </repository> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-psd</artifactId> <version>23.6</version> <classifier>jdk16</classifier> </dependency>
我們可以按照以下步驟輕松創(chuàng)建任何 PSD 文件的縮略圖:
以下代碼示例演示如何在 Java 中創(chuàng)建 PSD 文件的縮略圖。
// Load an existing PSD image PsdImage image = (PsdImage)Image.load("sample.psd"); int index = 0; // Iterate over the PSD resources for (int i =0; i <image.getImageResources().length; i++) { index++; // Check if the resource is of thumbnail type if (image.getImageResources()[i] instanceof ThumbnailResource) { // Retrieve the ThumbnailResource and Check the format of the ThumbnailResource ThumbnailResource thumbnail = (ThumbnailResource)image.getImageResources()[i]; if (thumbnail.getFormat()== ThumbnailFormat.KJpegRgb) { // Create a new image by specifying the width and height, Store the pixels of thumbnail on to the newly created image and save image PsdImage thumnailImage = new PsdImage(thumbnail.getWidth(), thumbnail.getHeight()); thumnailImage.savePixels(thumnailImage.getBounds(), thumbnail.getThumbnailData()); // Save thumbnail thumnailImage.save("Thumbnail_"+i+".jpg", new JpegOptions()); } } }
在這篇博文中,我們討論了如何用 Java 創(chuàng)建 PSD 縮略圖。我們使用 Aspose.PSD 庫來完成此任務(wù)。Aspose.PSD 庫是處理 PSD 文件的強大工具,可用于執(zhí)行各種任務(wù),例如創(chuàng)建縮略圖、編輯圖層以及將文件導(dǎo)出為其他格式。如果您正在尋找一個功能強大的 API 來在 Java 中處理 PSD 文件,那么 Aspose.PSD for Java 是一個不錯的選擇。
以上便是如何在 Java 中創(chuàng)建 PSD 縮略圖,希望能對您有所幫助,如果您還有其他疑問,歡迎查閱本系列其他教程,或者私信我們獲取幫助~
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn