Java API ソリューションを使用した EPS のサイズ変更

概要

この記事では、Java を使用して EPS ファイルのサイズを変更する 方法について説明します。以下のトピックを取り上げます。

Java で EPS をサイズ変更する方法

画像のサイズ変更は、画像の幅と高さのどちらか、または両方の寸法を変更する操作です。画像の内容はそのままですが、幅と高さの新しい値に応じて画像自体のサイズを変更できます。幅と高さが比例して増加した場合、EPS画像の表示は拡大され、そうでない場合は縮小されます。幅と高さが不均衡に変更された場合、結果として得られるEPS画像の表示は、ある方向に圧縮または引き伸ばされます。このソリューションはEPSファイルのコンテンツではなく、ヘッダーと設定セクションに基づいて動作するため、EPSファイルの容量はほとんど変わりません。

EPS画像の表示サイズを変更するには、多くの場合、既存のサイズを把握し、新しいサイズを割り当てる単位を選択する必要があります。単位は、ポイント(1/72インチ)、インチ、ミリメートル、センチメートル、パーセントです。 そこで、JavaでEPS画像のサイズを変更する手順は以下のとおりです。

  1. EPSファイルを含む入力ストリームを使用して、 PsDocument オブジェクトを初期化します。
  2. 静的メソッド extractEpsSize を使用して、画像の既存のサイズを抽出します。
  3. 結果の EPS ファイルの出力ストリームを作成します。
  4. 静的メソッド resizeEps を使用して、選択した Units を使用して、PsDocument オブジェクトのサイズを、選択した新しいサイズに変更します。

Aspose.Page EPS Resize の品質をチェックし、無料のオンライン Resize EPS で結果を表示し、その後、結果の EPS ファイルを EPS Viewer で表示できます。


JavaでEPSのサイズを変更し、ポイント単位で新しいサイズを設定

次のJavaコードスニペットでは、画像の新しいサイズはポイント(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でEPSのサイズを変更し、新しいサイズをパーセントで設定する

次のJavaコードスニペットでは、画像の新しいサイズがパーセントで設定されています。

 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);

.NET および C++ での EPS のサイズ変更を参照してください。

初期EPS画像


初期画像

サイズ変更済みEPS画像


サイズ変更済み画像

EPSサイズ変更Webアプリケーションで、オンラインでEPSのサイズ変更をお試しください。数秒でEPSファイルのサイズ変更と結果のダウンロードが可能です。

サンプルファイルとデータファイルは GitHubからダウンロードできます。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.