JPEG 到 PNG 的转换

Aspose.Imaging Cloud 是一个完整的图像格式处理 REST API。它提供了大量的图像处理选项,有关它可以处理的文件格式的详细信息可以在 支持的文件格式 中找到。在本文中,我们将讨论一些与流行图像格式的格式间转换相关的惊人功能。

GIF 到 DICOM 的转换

GIF 图像

图形交换格式 (GIF) 是一种位图图像,由于其高压缩率而广受欢迎。对于希望以最小文件大小制作动画图像的用户来说,它也是最受欢迎的格式之一。简而言之,GIF 是一系列图像或无声视频,它们会连续循环播放,不需要任何人按播放键。因此,它得到了广泛的支持,并且可在应用程序和操作系统之间移植。

DICOM 图像

同时,医学数字成像和通信 (DICOM) 是医学成像信息和相关数据的通信和管理标准。它们可以轻松提供医学成像设备(如扫描仪、服务器、工作站、打印机、网络硬件)的集成。因此,可能需要将 GIF 图像渲染为 DICOM 格式,为了实现此功能,可以使用 Aspose.Imaging Cloud。在以下步骤中,我们将使用在 Aspose.Imaging Cloud 之上开发的 Aspose.Imaging Cloud SDK for .NET

首先,可以使用包管理器控制台上的以下命令从 NuGet 库 安装 Aspose.Imaging Cloud SDK for .NET

Install-Package Aspose.Imaging-Cloud -Version 21.2.0

您也可以访问以下链接获取有关如何安装 Aspose.Cloud SDKs的更多信息。

除了使用 .NET Cloud SDK,还可以通过终端上的 cURL 命令访问 Cloud API 来实现此要求。但是,为了访问 Cloud API,您需要生成 JWT 访问令牌,因为只有授权用户才能访问 API。有关更多信息,请访问 如何使用客户端 ID 和客户端密钥获取 JWT 令牌

cURL 命令

curl -v "https://api.aspose.cloud/v3.0/imaging/kite.gif/convert?format=DICOM" \
-X GET \
-H "Accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-o /Users/nayyershahbaz/Documents/myResultant.dicom

在下面给出的代码片段中,我们使用 Aspose.Imaging Cloud SDK for .NET 执行 GIF 图像到 DICOM 的转换。

  • 首先,我们需要创建一个 ImagingApi 对象,并将 ClientID 和 ClientSecret 详细信息作为构造函数的输入参数。
  • 调用方法 ConvertImageRequest(..),绕过源图像、结果格式、文件夹和存储作为输入参数
  • 调用方法 ConvertImage(..) 执行转换
  • 最后,我们将调用 File.Create(..) 方法将输出保存在本地驱动器上。

.NET 教程

String MyClientID = "c235e685-1aab-4cda-a95b-54afd63eb87f"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/
String MyClientSecret = "b8da4ee37494f2ef8da3c727f3a0acb9"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/

ImagingApi imagingApi = new ImagingApi(MyClientSecret, MyClientID,"https://api.aspose.cloud");

// 请参阅https://docs.aspose.cloud/display/imagingcloud/Supported+File+Formats
// 可能的输出格式
string format = "dicom";
string folder = null; // Input file is saved at the root of the storage
string storage = null; // Cloud Storage name

var request = new Aspose.Imaging.Cloud.Sdk.Model.Requests.ConvertImageRequest("kite.gif", format, folder, storage);
Stream updatedImage = imagingApi.ConvertImage(request);

// 将更新后的图像保存到本地存储
using (var fileStream = File.Create("/Users/nayyershahbaz/Documents/myResultant." + format))
{
    updatedImage.Seek(0, SeekOrigin.Begin);
    updatedImage.CopyTo(fileStream);
}

上述示例中使用的源图像可以从以下位置下载

将 JPEG 转换为 PNG

JPEG 格式

联合图像专家组 (JPEG) 图像是网络上存储和传输摄影图像的流行选择。现在几乎所有操作系统都支持可视化 JPEG 图像的查看器。它也是一种著名的有损压缩方法,使用户可以在存储大小和图像质量之间进行选择权衡。由于这些功能,JPEG 图像在很大程度上推动了互联网以及后来的社交媒体上数字图像和数字照片的激增。

PNG 格式

尽管 JPEG 是流行的格式之一,但有时某些应用程序仅支持便携式网络图形 (PNG) 格式时会存在要求。PNG 格式也是一种光栅图形文件格式,支持无损数据压缩,保持颜色之间的细节和对比度。特别是,PNG 比 JPEG 提供了更好的文本可读性。这使得 PNG 成为信息图表、横幅、屏幕截图和其他包含图像和文本的图形的更受欢迎的选择。因此,为了满足此要求,您可以尝试使用 Aspose.Imaging Cloud API 的 ConvertImage(..) 方法。

cURL 命令 - 带存储

curl -v "https://api.aspose.cloud/v3.0/imaging/Converter.jpg/convert?format=PNG" \
-X GET \
-H "Accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-o /Users/nayyershahbaz/Documents/myResultant.png

下面给出的是 C# .NET 代码片段,提供将输入的 JPEG 图像渲染为 PNG 格式的功能。

.NET 教程

String MyClientID = "c235e685-1aab-4cda-a95b-54afd63eb87f"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/
String MyClientSecret = "b8da4ee37494f2ef8da3c727f3a0acb9"; // Get AppKey and AppSID from https://dashboard.aspose.cloud/


ImagingApi imagingApi = new ImagingApi(MyClientSecret, MyClientID,"https://api.aspose.cloud");

// 请参阅https://docs.aspose.cloud/display/imagingcloud/Supported+File+Formats
// 可能的输出格式
string format = "png";
string folder = null; // Input file is saved at the root of the storage
string storage = null; // Cloud Storage name

var request = new Aspose.Imaging.Cloud.Sdk.Model.Requests.ConvertImageRequest("Converter.jpg", format, folder, storage);
Stream updatedImage = imagingApi.ConvertImage(request);

// 将更新后的图像保存到本地存储
using (var fileStream = File.Create("/Users/nayyershahbaz/Documents/myResultant." + format))
{
    updatedImage.Seek(0, SeekOrigin.Begin);
    updatedImage.CopyTo(fileStream);
}

快速提示

为了查看图像文件,您可以尝试使用我们的 Aspose.Imaging Viewer App,它是 100% 免费的。无需订阅或登录。

结论

在本文中,我们了解了 Aspose.Imaging Cloud API 的功能,用于将一种图像格式转换为另一种格式。快速技巧是,您可以使用相同的 ConvertImage(…) 方法将任何已有的图像渲染为其他受支持的格式。类似地,使用 CreateConvertedImage(…) 方法从输入目录加载图像并将其渲染为其他受支持的格式,即将 JPEG 转换为 PNG 等。与上面提到的转换功能类似,可以使用相同的方法将 CDR 转换为 PNG 和将 EMF 转换为 SVG