调整 EPS 大小 | .NET API 解决方案
概述
本文讲解如何使用 C# 调整 EPS 大小。内容涵盖以下主题:
- C# 调整 EPS 大小说明
- C# 调整 EPS 大小,以点为单位设置新大小
- C# 调整 EPS 大小,以英寸为单位设置新大小
- C# 调整 EPS 大小,以毫米为单位设置新大小
- C# 调整 EPS 大小,以百分比为单位设置新大小
C# 调整 EPS 大小说明
调整图像大小的操作会改变图像的宽度和高度中的一个或两个维度。图像内容保持不变,但图像本身可以根据新的宽度和高度值进行缩放。如果宽度和高度按比例增加,EPS 图像的显示效果会放大,否则会缩小。如果宽度和高度变化不成比例,则 EPS 图像的显示效果会在某个方向上被压缩或拉长。由于我们的解决方案不处理内容,而是处理 EPS 文件的标题和设置部分,因此 EPS 文件的体积几乎保持不变。
要设置 EPS 图像显示效果的新尺寸,通常需要知道其现有尺寸并选择指定新尺寸的单位。单位可以是点(1/72 英寸)、英寸、毫米、厘米和百分比。 因此,在 C# 中调整 EPS 图像大小的步骤如下:
- 使用包含 EPS 文件的输入流初始化 PsDocument 对象。
- 使用静态方法 ExtractEpsSize 提取图像的现有尺寸。
- 为生成的 EPS 文件创建输出流。
- 使用静态方法 ResizeEps,以选定的 单位 调整 PsDocument 对象的大小,使其达到新的尺寸。
您可以通过免费在线 Resize EPS 检查 Aspose.Page EPS Resize 的质量并查看结果,然后使用我们的 EPS Viewer 查看生成的 EPS 文件。
在 C# 中以 Points 为单位调整 EPS 图像大小
以下 C# 代码片段中,图像的新大小以 Points(1/72 英寸)为单位设置:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6
7//Initialize PsDocument object with EPS file
8PsDocument doc = new PsDocument(dataDir + "input.eps");
9
10//Get size of EPS image
11Size oldSize = doc.ExtractEpsSize();
12
13//Create an output stream for resized EPS
14using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_inches.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
15{
16 //Save EPS to the output stream with new size assigned in inches
17 doc.ResizeEps(outputEpsStream, new SizeF(oldSize.Width * 2, oldSize.Height * 2), Units.Points);
18}
对于 Linux、MacOS 和其他非 Windows 操作系统,我们建议使用我们的 Aspose.Page.Drawing Nuget 软件包。它使用 Aspose.Drawing 后端,而不是 System.Drawing 系统库。
因此,请导入 Aspose.Page.Drawing 命名空间,而不是 System.Drawing 命名空间。在以上和以下代码片段中,将使用 Aspose.Page.Drawing.Size 代替 System.Drawing.Size。我们在 GitHub 上的代码示例包含所有必要的替换。
在 C# 中调整 EPS 大小,以英寸为单位设置新尺寸
在以下 C# 代码片段中,图像的新尺寸以英寸为单位设置:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6 //Create an input stream for EPS file
7using (Stream inputEpsStream = new System.IO.FileStream(dataDir + "input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read))
8{
9 //Initialize PsDocument object with input stream
10 PsDocument doc = new PsDocument(inputEpsStream);
11
12 //Get size of EPS image
13 Size oldSize = doc.ExtractEpsSize();
14
15 //Create an output stream for resized EPS
16 using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_inches.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
17 {
18 //Save EPS to the output stream with new size assigned in inches
19 doc.ResizeEps(outputEpsStream, new SizeF(5.791f, 3.625f), Units.Inches);
20 }
21}
在 C# 中调整 EPS 图像尺寸,以毫米为单位
以下 C# 代码片段中,图像的新尺寸以毫米为单位:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6 //Create an input stream for EPS file
7using (Stream inputEpsStream = new System.IO.FileStream(dataDir + "input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read))
8{
9 //Initialize PsDocument object with input stream
10 PsDocument doc = new PsDocument(inputEpsStream);
11
12 //Get size of EPS image
13 Size oldSize = doc.ExtractEpsSize();
14
15 //Create an output stream for resized EPS
16 using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_mms.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
17 {
18 //Save EPS to the output stream with new size assigned in millimeters
19 doc.ResizeEps(outputEpsStream, new SizeF(196, 123), Units.Millimeters);
20 }
21}
在 C# 中通过百分比设置 EPS 图像的新尺寸
以下 C# 代码片段中,图像的新尺寸由百分比设置:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6 //Create an input stream for EPS file
7using (Stream inputEpsStream = new System.IO.FileStream(dataDir + "input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read))
8{
9 //Initialize PsDocument object with input stream
10 PsDocument doc = new PsDocument(inputEpsStream);
11
12 //Get size of EPS image
13 Size oldSize = doc.ExtractEpsSize();
14
15 //Create an output stream for resized EPS
16 using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_mms.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
17 {
18 //Save EPS to the output stream with new size assigned in percents
19 doc.ResizeEps(outputEpsStream, new SizeF(200, 200), Units.Percents);
20 }
21}
初始图像
调整大小的图像
在我们的调整 EPS 大小 Web 应用程序上在线评估调整 EPS 大小。您可以在几秒钟内调整 EPS 文件大小并下载结果。
您可以从 GitHub 下载示例和数据文件。