Java API ソリューションを使用した EPS のサイズ変更
概要
この記事では、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 を使用して、選択した Units を使用して、PsDocument オブジェクトのサイズを、選択した新しいサイズに変更します。
Aspose.Page EPS Resize の品質をチェックし、無料のオンライン Resize EPS で結果を表示し、その後、結果の EPS ファイルを EPS Viewer で表示できます。
JavaでEPSのサイズを変更し、ポイント単位で新しいサイズを設定
次のJavaコードスニペットでは、画像の新しいサイズはポイント(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で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_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からダウンロードできます。