在这篇基础文章中,您将学习如何使用 NET REST API 将 JPG 转换为 PSD。我们将按照以下部分中提到的详细步骤,使用 C# Low Code API 创建 JPG 到 PSD 转换器。创建的应用程序代码可以与 Windows、macOS 或 Linux 环境中支持的任何 .NET 应用程序集成,并且可以免费进行转换。
先决条件
创建账户并获取 API 凭证 执行 JPG 到 PSD 的转换
下载 Aspose.Imaging Cloud SDK for .NET to convert JPG to PSD
使用上述 SDK 设置 C# .NET 项目,将 JPG 渲染为 PSD
使用 NET REST API 将 JPG 转换为 PSD 的步骤
- 设置 API 的客户端 ID 和客户端密钥以将 JPG 转换为 PSD
- 使用客户端凭据创建 ImagingAPI 类的实例,以执行 JPG 到 PSD 的转换
- 指定源 JPG 和输出 PSD 文件名
- 访问并加载示例 JPG 文件并将其上传到云存储
- 使用输入 JPG 文件流和输出 PSD 格式创建 ConvertImageRequest 实例
- 调用 ConvertImage 方法使用 NET REST API 将 JPG 转换为 PSD
- 将返回的PSD文件流保存在本地磁盘
下面将介绍使用 C# Low Code API 将文件类型从 JPG 导出为 PSD 的过程。我们将使用 ImagingAPI 类的实例来初始化 SDK。然后,我们将使用磁盘中的 FileStream 加载源 JPG 文件,然后使用 ConvertImageRequest 类实例通过 ConvertImage() 方法执行转换为 PSD。
使用 NET Low Code API 进行 JPG 到 PSD 转换的代码
using Aspose.Imaging.Cloud.Sdk.Api; | |
using Aspose.Imaging.Cloud.Sdk.Model.Requests; | |
using Aspose.Imaging.Cloud.Sdk.Model; | |
using System; | |
using System.IO; | |
namespace Kb_Aspose.KB | |
{ | |
public class JpgToPsdConverter | |
{ | |
public void JpgToPsd() | |
{ | |
var clientID = "Client ID"; | |
var clientSecret = "Client Secret"; | |
var apiBaseUrl = "https://api.aspose.cloud"; | |
var localPath = "C:/Words/"; | |
var jpgToPsdImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl); | |
// Source and output file names | |
var inputFileName = "Sample.jpg"; | |
var outputFileName = "JpgtoPsd.psd"; | |
var outputFormat = "psd"; | |
var remoteFolder = null; // source file is saved at the root of the storage | |
var remoteStorage = null; // remote cloud Storage place name | |
try | |
{ | |
// Upload the local image to Cloud Storage | |
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open); | |
inpuFileStream.Position = 0; | |
var uploadJpgFileRequest = new UploadFileRequest(inputFileName, inpuFileStream, null); | |
jpgToPsdImageApi.UploadFile(uploadJpgFileRequest); | |
var convertJpgToPsdRequest = new ConvertImageRequest(inputFileName, outputFormat, | |
remoteFolder, remoteStorage); | |
var psdDataStream = jpgToPsdImageApi.ConvertImage(convertJpgToPsdRequest); | |
psdDataStream.Position = 0; | |
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat)) | |
{ | |
psdDataStream.Seek(0, SeekOrigin.Begin); | |
psdDataStream.CopyTo(fileStream); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
这个精确的代码示例演示了如何使用 C# Cloud API 将 JPG 转换为 PSD。完成先决条件步骤后,您必须提供访问磁盘上源 JPG 图像的路径,并使用 Aspose.Imaging REST API SDK 执行渲染到 PSD。转换完成后,生成的 PSD 图像文件流将作为响应接收,然后您可以将其本地保存在磁盘上。
在本文中,我们介绍了如何使用 Cloud API 将 JPG 转换为 PSD。如果您有兴趣执行 JPG 到 PNG 的转换,请参阅有关如何操作 使用 NET REST API 将 JPG 转换为 PNG 的文章。