如何使用 Java REST API 将 JPG 转换为 PSD

以下分步教程向您展示了如何使用 Java REST API 将 JPG 转换为 PSDJPG(也称为 JPEG)是一种用于压缩和存储数字图像的文件格式标准。它最常用于数码照片,也是数码相机和其他图像捕捉设备最常用的图像格式。该格式通过消除冗余数据和使用数据压缩算法来压缩文件,这些算法可以在不显着影响图像质量的情况下减小文件的大小。

同时,PSD(Photoshop 文档)文件是 Photoshop 用于保存数据的默认格式。它是 Adobe 开发的一种专有文件格式,包含位图图像和图像组件,例如带蒙版的图层、色彩空间、ICC 配置文件、透明度、文本、alpha 通道和专色。 PSD 文件通常用于为网站和其他数字媒体创建图形和徽标。如果您希望在 Java 低代码 API 中将 JPG 转换为 PSD,则可以借助以下示例执行此操作。

先决条件

在 Java REST API 中将 JPG 转换为 PSD 的步骤

  1. 为 API 设置客户端 ID 和客户端密码
  2. 使用客户端凭据创建 ImagingAPI 类的对象
  3. 指定输入和输出文件
  4. 读取输入的JPG文件并上传到云存储
  5. 使用输入和输出文件格式创建 ConvertImageRequest 对象
  6. 调用 convertImage 方法以使用 REST API 将 JPG 转换为 PSD
  7. 将输出的 PSD 文件保存到本地磁盘

Java Low Code API 中 JPG 到 PSD 转换的代码

String ClientID = Client.getID(); //replace Client.getID() with your own client ID here
String ClientSecret = Client.getSecret(); //replace Client.getSecret() with your own client secret here
String APIBaseUrl="https://api.aspose.cloud";
String Local_Path = "C:/Temp/";
ImagingApi imagingApiSdk = new ImagingApi(ClientSecret, ClientID, APIBaseUrl);
// Input & output file names
String inputFileName = "JPGtoPSD.jpg";
String outputFileName = "JPGtoPSD.psd";
try {
// Upload local image to Cloud Storage
File inputFile = new File(Local_Path + inputFileName);
FileInputStream inputFileStream = new FileInputStream(inputFile);
byte[] inputImageData = IOUtils.toByteArray(inputFileStream);
UploadFileRequest uploadFileRequest = new UploadFileRequest(inputFileName, inputImageData, null);
FilesUploadResult filesUploadResult = imagingApiSdk.uploadFile(uploadFileRequest);
String outputFormat = "psd";
String remoteFolder = null; // Input file is saved at the root of the storage
String remoteStorage = null; // Cloud Storage name
ConvertImageRequest convertImageRequest = new ConvertImageRequest(inputFileName, outputFormat, remoteFolder, remoteStorage);
byte[] convertedImageData = imagingApiSdk.convertImage(convertImageRequest);
// Save exported image to local storage
FileOutputStream fileOutputStream = new FileOutputStream(Local_Path + outputFileName);
fileOutputStream.write(convertedImageData);
fileOutputStream.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}

此页面上提供的代码片段可帮助您使用 Java REST API 将 JPG 转换为 PSD。您只需在 Aspose.Imaging REST API SDK 的帮助下提供 JPG 文件并下载输出 PSD 文件以将其保存在本地。

这个 JPG 到 PSD 的转换功能可以被 Windows、Linux 或 Mac 上的任何无代码或低代码应用程序利用。

以下链接显示了可能对您有帮助的类似功能:如何使用 Java REST API 将 GIF 转换为 PSD

 简体中文