图像处理控件Aspose.page功能演示:将 PostScript 转换为 GIF

现在将PostScript文件转换为高质量图像并不是一件难事。Aspose.Page为多种编程语言提供高代码 API,以便以编程方式转换和操作 PS 文件。此外,它还支持企业级在线PS文件转换器,以将 PS 文件转换为其他流行的文件格式。但是,本指南适用于正在寻找PostScript Java库以编程方式将 PostScript 转换为GIF 的Java 程序员。您几乎可以在所有流行的操作系统上轻松打开 GIF 图像,而无需安装软件。那么,让我们开始吧。

Aspose.Page for Java - 用于XPS,PS和EPS的Java文件操作API,允许用户创建,解析和保存XPS文件,以及在文档中添加和删除页面。允许将PS和EPS文件转换为PDF和光栅图像格式。允许开发人员为XPS文档创建画布,路径和字形元素,并执行诸如添加或删除页面,创建矢量和字符串,使用画笔以及操纵元素外观等操

Aspose.Page 最新下载icon-default.png?t=N7T8https://work.weixin.qq.com/ca/cawcde843d00f8661d

PostScript Java 库安装

为了安装Aspose.Page for Java,您可以 下载JAR 文件或使用以下 Maven 配置:

<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-page</artifactId>
<version>23.12</version>
</dependency>
</dependencies>

此外,您可以访问此安装指南来了解完整的详细信息。

PostScript Java 库

使用 Java 将 PostScript 转换为 GIF - 代码示例

现在,您可以开发一款 PS 转 GIF 制作器,用于商业软件。因此,请按照以下步骤操作:

  • 将 ImageFormat 设置为GIF并加载源 PostScript 文件。
  • 使用 PostScript 输入流初始化PsDocument类的对象。
  • 如果您想转换 Postscript 文件而不顾小错误,请设置 suppressErrors 的值。
  • 使用 suppressErrors 参数实例化ImageSaveOptions类的新对象。
  • 创建ImageDevice类的实例。
  • 调用save方法将GIF文件保存到磁盘上。
  • 调用getImagesBytes方法以字节为单位获取结果图像。
  • 通过使用输出图像路径初始化 FileOutputStream 类的实例来创建输出流。

以下代码示例演示了如何以编程方式在 Java 中将 PostScript 转换为 GIF

package com.example;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import com.aspose.eps.PsDocument;
import com.aspose.eps.device.ImageDevice;
import com.aspose.eps.device.ImageSaveOptions;

public class Main {
// High Code Java API to Convert PostScript to GIF
public static void main(String[] args) throws Exception {
// Set the ImageFormat to GIF.
com.aspose.page.ImageFormat imageFormat = com.aspose.page.ImageFormat.GIF;
// Load the source PostScript file.
FileInputStream psStream = new FileInputStream("/input.ps");
// Initialize an object of the PsDocument class with the PostScript input stream.
PsDocument document = new PsDocument(psStream);
// Set the value of suppressErrors if you want to convert the Postscript file despite minor errors.
boolean suppressErrors = true;
// Instantiate a new object of ImageSaveOptions class with suppressErrors parameter.
ImageSaveOptions options = new ImageSaveOptions(suppressErrors);
// Create an instance of the ImageDevice class.
ImageDevice device = new ImageDevice();
try {
// Call the save method to save the GIF file on the disk.
document.save(device, options);
} finally {
psStream.close();
}
// Invoke the getImagesBytes method to get the resulting images in bytes.
byte[][] imagesBytes = device.getImagesBytes();
int i = 0;
for (byte [] imageBytes : imagesBytes) {
String imagePath = "/PSToGIF" + i + "." + imageFormat.toString().toLowerCase();
// Create output stream by initializing an instance of the FileOutputStream class with the output image path.
FileOutputStream fs = new FileOutputStream(imagePath);

try {
fs.write(imageBytes, 0, imageBytes.length);
} catch (IOException ex) {
System.out.println(ex.getMessage());
} finally {
fs.close();
}
i++;
}

//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
}
}

您可以在下图中看到输出:

从图片中制作 GIF

PS 文件转换器 - 在线工具

在线工具提供丰富的 PS 到其他广泛使用的文件格式的转换功能。它由Aspose.Page提供支持,是一款免费工具。此外,它在转换为其他文件格式时保持文本和图形数据的质量。我们强烈建议您使用此PS 文件转换器来提高工作效率。

PS 文件转换器

结论

综上所述,我们已经了解了如何以编程方式在 Java 中将 PostScript 转换为 GIF。此外,我们还实现了开发高效PS 文件转换器的功能。同样,您可以通过访问文档、GitHub repo和 API参考来进一步探索此 PostScript Java 库。

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值