下面的简短教程详细说明了如何使用 Java REST API 将 BMP 转换为 PSD。 BMP(位图)是一种光栅图像文件格式,用于存储位图数字图像,独立于显示设备(例如图形适配器),尤其是在 Microsoft Windows 和 OS/2 操作系统上。 BMP 文件格式能够存储高达 24 位色深的 2D 数字图像。 BMP 图像通常是未压缩的,但可以使用一些无损压缩算法进行压缩,包括 RLE 和霍夫曼编码。
另一方面,PSD 是 Photoshop Document 的缩写,是 Photoshop 用于保存数据的默认格式。 PSD 文件是包含高质量图形数据的 Adobe Photoshop 文件,包括图层、通道、路径和其他元素。它们通常用于网页和印刷设计,以及创建用于其他应用程序的图像。如果您需要在 Java 低代码 API 中将 BMP 转换为 PSD,则可以借助以下代码执行此操作。
先决条件
- 创建帐户并获取 API 凭据
- 下载 Aspose.Imaging Cloud SDK for Java
- 使用上述 SDK 设置 Java 项目
在 Java REST API 中将 BMP 转换为 PSD 的步骤
- 为 API 设置客户端 ID 和客户端密码
- 使用客户端凭据创建 ImagingAPI 类的对象
- 指定输入和输出文件
- 读取输入的BMP文件并上传到云存储
- 使用输入和输出文件格式创建 ConvertImageRequest 对象
- 调用 convertImage 方法以使用 REST API 将 BMP 转换为 PSD
- 将输出的 PSD 文件保存到本地磁盘
Java Low Code API 中 BMP 到 PSD 转换的代码
String ClientID = Client.getID(); //replace Client.getID() with your own client ID here | |
String ClientSecret = Client.getSecret(); //replace3 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 = "BMPtoPSD.bmp"; | |
String outputFileName = "BMPtoPSD.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 将 BMP 转换为 PSD。您只需借助 Aspose.Imaging REST API SDK 提供 BMP 文件并下载输出 PSD 文件以将其保存在本地。
此 BMP 到 PSD 的转换功能可用于 Windows、Linux 或 Mac 上的任何无代码或低代码应用程序。
以下主题探讨了同样有用的类似功能:如何使用 Java REST API 将 JPEG2000 转换为 PDF