使用 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// Setting new size of EPS file in points.
2
3// Initialize PS document with EPS file
4PsDocument document = new PsDocument(getDataDir() + "input.eps");
5
6String outputFileName = "output_resize_points.eps";
7
8//Get size of EPS image
9Dimension oldSize = document.extractEpsSize();
10
11//Increase EPS size in 2 times and save to new file
12document.resizeEps(getOutputDir() + outputFileName,
13 new DimensionF(oldSize.width * 2, oldSize.height * 2), Units.Points);在 Java 中调整 EPS 图像尺寸,以英寸为单位
以下 Java 代码片段中,图像的新尺寸以英寸为单位:
1// Setting new size of EPS file in inches.
2
3// Initialize PS document with EPS file
4PsDocument document = new PsDocument(getDataDir() + "input.eps");
5
6String outputFileName = "output_resize_inches.eps";
7
8//Get size of EPS image
9Dimension oldSize = document.extractEpsSize();
10
11//Save EPS file with new name and new size assigned in inches
12document.resizeEps(getOutputDir() + outputFileName,
13 new DimensionF(5.791f, 3.625f), Units.Inches);在 Java 中调整 EPS 图像尺寸(以毫米为单位)
以下 Java 代码片段中,图像的新尺寸以毫米为单位:
1// Setting new size of EPS file in millimeters.
2
3// Initialize PS document with EPS file
4PsDocument document = new PsDocument(getDataDir() + "input.eps");
5
6String outputFileName = "output_resize_mms.eps";
7
8//Get size of EPS image
9Dimension oldSize = document.extractEpsSize();
10
11//Save EPS file with new name and new size assigned in millimeters
12document.resizeEps(getOutputDir() + outputFileName,
13 new DimensionF(196, 123), Units.Millimeters);在 Java 中通过 Percents 设置 EPS 图像的新尺寸
以下 Java 代码片段中,图像的新尺寸由 Percents 设置:
1// Setting new size of EPS file in percents of original size.
2
3// Initialize PS document with EPS file
4PsDocument document = new PsDocument(getDataDir() + "input.eps");
5
6String outputFileName = "output_resize_percents.eps";
7
8//Get size of EPS image
9Dimension oldSize = document.extractEpsSize();
10
11//Save EPS file with new name and new size assigned in percents of original size
12document.resizeEps(getOutputDir() + outputFileName,
13 new DimensionF(200, 200), Units.Percents);
初始图像

调整大小的图像
在我们的调整 EPS 大小 Web 应用程序上在线评估调整 EPS 大小。您可以在几秒钟内调整 EPS 文件大小并下载结果。
您可以从 GitHub下载示例和数据文件。