使用 Java API 解决方案调整 EPS 大小
Contents
[
Hide
Show
]概述
本文讲解如何使用 Java 调整 EPS 图像大小。内容涵盖以下主题:
- Java 调整 EPS 图像大小说明
- Java 调整 EPS 图像大小,以点为单位
- Java 调整 EPS 图像大小,以英寸为单位
- Java 调整 EPS 图像大小,以毫米为单位
- Java 调整 EPS 图像大小,以百分比为单位
Java 调整 EPS 图像大小说明
调整图像大小是指改变图像宽度和高度(或两者)的操作。图像内容保持不变,但图像本身可以根据宽度和高度的新值进行缩放。如果宽度和高度按比例增加,EPS 图像的显示将会放大,否则将会缩小。如果宽度和高度变化不成比例,最终的 EPS 图像会在某个方向上被压缩或拉长。由于我们的解决方案不处理内容,而是处理 EPS 文件的标题和设置部分,因此 EPS 文件的体积几乎保持不变。
要设置 EPS 图像的新尺寸,通常需要知道其现有尺寸并选择用于指定新尺寸的单位。单位可以是磅(1/72 英寸)、英寸、毫米、厘米和百分比。 因此,在 Java 中调整 EPS 图像大小的步骤如下:
- 使用包含 EPS 文件的输入流初始化 PsDocument 对象。
- 使用静态方法 extractEpsSize 提取图像的现有大小。
- 为生成的 EPS 文件创建输出流。
- 使用静态方法 resizeEps 以选定的 单位 调整 PsDocument 对象的大小,使其达到新的大小。
您可以通过免费在线 Resize EPS 检查 Aspose.Page EPS Resize 的质量并查看结果,然后使用我们的 EPS Viewer 查看生成的 EPS 文件。
在 Java 中以 Points 为单位调整 EPS 图像大小
以下 Java 代码片段中,图像的新大小以 Points(1/72 英寸)为单位设置:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Get size of EPS image
13Dimension oldSize = doc.extractEpsSize();
14
15//Create output stream for PostScript document
16FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_points.eps");
17
18//Increase EPS size in 2 times and save to the output stream
19doc.resizeEps(outputEpsStream, new DimensionF(oldSize.width * 2, oldSize.height * 2), Units.Points);
在 Java 中调整 EPS 图像尺寸,以英寸为单位
以下 Java 代码片段中,图像的新尺寸以英寸为单位:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Get size of EPS image
13//Dimension oldSize = doc.extractEpsSize();
14
15//Create output stream for PostScript document
16FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_inches.eps");
17
18//Save EPS to the output stream with new size assigned in inches
19doc.resizeEps(outputEpsStream, new DimensionF(5.791f, 3.625f), Units.Inches);
在 Java 中调整 EPS 图像尺寸(以毫米为单位)
以下 Java 代码片段中,图像的新尺寸以毫米为单位:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Create output stream for PostScript document
13FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_mms.eps");
14
15//Save EPS to the output stream with new size assigned in millimeters
16doc.resizeEps(outputEpsStream, new DimensionF(196, 123), Units.Millimeters);
在 Java 中通过 Percents 设置 EPS 图像的新尺寸
以下 Java 代码片段中,图像的新尺寸由 Percents 设置:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Create output stream for PostScript document
13FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_percents.eps");
14
15//Save EPS to the output stream with new size assigned in percents
16doc.resizeEps(outputEpsStream, new DimensionF(200, 200), Units.Percents);
初始图像
调整大小的图像
在我们的调整 EPS 大小 Web 应用程序上在线评估调整 EPS 大小。您可以在几秒钟内调整 EPS 文件大小并下载结果。
您可以从 GitHub下载示例和数据文件。