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 を使用して、選択した Units の新しいサイズでPsDocument オブジェクトのサイズを変更します。
Aspose.Page EPS Resize の品質を確認し、無料のオンラインツール Resize EPS で結果を表示し、その後、弊社の EPS Viewer で結果の EPS ファイルを表示できます。
C# で EPS のサイズを変更し、新しいサイズをポイント単位で設定する
次の C# コードスニペットでは、画像の新しいサイズはポイント(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パッケージをご利用いただけます。このパッケージは、System.Drawingシステムライブラリではなく、Aspose.Drawingバックエンドを使用します。
そのため、System.Drawing名前空間ではなく、Aspose.Page.Drawing名前空間をインポートしてください。上記および以下のコードスニペットでは、System.Drawing.SizeではなくAspose.Page.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 からダウンロードできます。