翻譯|使用教程|編輯:張瑩心|2021-11-03 11:27:14.517|閱讀 263 次
概述:PSD圖像文件用于為徽標、橫幅、小冊子和許多其他目的設計圖片。在某些情況下,您可能需要在 Java 應用程序中裁剪或旋轉 PSD 文件。本文介紹了如何使用 Java 以編程方式裁剪或旋轉 PSD 文件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PSD圖像文件用于為徽標、橫幅、小冊子和許多其他目的設計圖片。在某些情況下,您可能需要在 Java 應用程序中裁剪或旋轉 PSD 文件。本文介紹了如何使用 Java 以編程方式裁剪或旋轉 PSD 文件。您需要配置Aspose.PSD for Java API才能使用幾種受支持的文件格式。如果你還沒有用過Aspose.PSD可以點擊這里下載最新版測試。
// Load an existing image into an instance of RasterImage class
RasterImage rasterImage = (RasterImage)Image.load("Test.psd");
// Before cropping, the image should be cached for better performance
if (!rasterImage.isCached())
{
rasterImage.cacheData();
}
// Define shift values for all four sides
int leftShift = 10;
int rightShift = 10;
int topShift = 10;
int bottomShift = 10;
// Based on the shift values, apply the cropping on image.
// Crop method will shift the image bounds toward the center of image and Save the results to disk
rasterImage.crop(leftShift, rightShift, topShift, bottomShift);
// Save output in JPEG,PSD or any other format.
rasterImage.save("output.jpg", new JpegOptions());
rasterImage.save("output.psd", new PsdOptions());
String sourceFile = "sample.psd";
String destName = "Cropping-PSD_out.jpg";
// Load an existing image into an instance of RasterImage class
RasterImage rasterImage = (RasterImage)Image.load(sourceFile);
// Cache the image for better performance
if (!rasterImage.isCached())
{
rasterImage.cacheData();
}
// Create an instance of Rectangle class with desired size.
Rectangle rectangle = new Rectangle(20, 20, 20, 20);
// Perform the crop operation on object of Rectangle class
rasterImage.crop(rectangle);
// Save the results to disk
rasterImage.save(destName, new JpegOptions());
String sourceFile = "sample.psd";
String destName = "Rotate-PSD_out.jpg";
// Load input PSD image file
RasterImage image = (RasterImage)Image.load(sourceFile);
// Before rotation, the image should be cached for better performance
if (!image.isCached())
{
image.cacheData();
}
// Rotate the PSD image on 20 degree angle while keeping the image size proportional with red background color
image.rotate(20f, true, Color.getRed());
// Save the result to a new file
image.save(destName, new JpegOptions());
如果你想試用Aspose的全部完整功能,可 聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn