EPS のサイズ変更 | C++ 向け API ソリューション

概要

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

C++ による EPS のサイズ変更の説明

画像のサイズ変更は、画像の幅と高さのいずれか、または両方の寸法を変更する操作です。画像の内容はそのままですが、画像自体は幅と高さの新しい値に応じて拡大縮小できます。幅と高さが比例して増加した場合、EPS 画像の表現は拡大され、そうでない場合は縮小されます。幅と高さが不比例に変更された場合、結果として得られる EPS 画像の表現は、ある方向に圧縮または引き伸ばされます。このソリューションは EPS ファイルのコンテンツではなく、ヘッダーと設定セクションに基づいて動作するため、EPS ファイルの容量はほとんど変わりません。 EPS 画像の表示サイズを新しく設定するには、多くの場合、既存のサイズを把握し、新しいサイズを割り当てる単位を選択する必要があります。ポイント(1/72インチ)、インチ、ミリメートル、センチメートル、パーセントが使用できます。 C++ で EPS 画像をリサイズする手順は以下のとおりです。

  1. EPS ファイルを含む入力ストリームを使用して PsDocument オブジェクトを初期化します。
  2. 静的メソッド ExtractEpsSize を使用して、画像の既存のサイズを抽出します。
  3. 結果の EPS ファイルの出力ストリームを作成します。
  4. 静的メソッド 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-C
 2
 3    // The path to the documents directory.
 4    System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
 5    
 6    //Create an input stream for EPS file
 7    {
 8        System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
 9        // Clearing resources under 'using' statement
10        System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
11        // ------------------------------------------
12        
13        try
14        {
15            //Initialize PsDocument object with input stream
16            System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
17            
18            //Get size of EPS image
19            System::Drawing::Size oldSize = doc->ExtractEpsSize();
20            
21            //Create an output stream for resized EPS
22            {
23                System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output_resize_points.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
24                // Clearing resources under 'using' statement
25                System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
26                // ------------------------------------------
27                
28                try
29                {
30                    //Increase EPS size in 2 times and save to the output stream
31                    doc->ResizeEps(outputEpsStream, System::Drawing::SizeF(static_cast<float>(oldSize.get_Width() * 2), static_cast<float>(oldSize.get_Height() * 2)), Aspose::Page::Units::Points);
32                }
33                catch(...)
34                {
35                    __dispose_guard_0.SetCurrentException(std::current_exception());
36                }
37            }
38        }
39        catch(...)
40        {
41            __dispose_guard_1.SetCurrentException(std::current_exception());
42        }
43    }

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-C
 2
 3    // The path to the documents directory.
 4    System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
 5    
 6    //Create an input stream for EPS file
 7    {
 8        System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
 9        // Clearing resources under 'using' statement
10        System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
11        // ------------------------------------------
12        
13        try
14        {
15            //Initialize PsDocument object with input stream
16            System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
17            
18            //Get size of EPS image
19            System::Drawing::Size oldSize = doc->ExtractEpsSize();
20            
21            //Create an output stream for resized EPS
22            {
23                System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output_resize_inches.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
24                // Clearing resources under 'using' statement
25                System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
26                // ------------------------------------------
27                
28                try
29                {
30                    //Save EPS to the output stream with new size assigned in inches
31                    doc->ResizeEps(outputEpsStream, System::Drawing::SizeF(5.791f, 3.625f), Aspose::Page::Units::Inches);
32                }
33                catch(...)
34                {
35                    __dispose_guard_0.SetCurrentException(std::current_exception());
36                }
37            }
38        }
39        catch(...)
40        {
41            __dispose_guard_1.SetCurrentException(std::current_exception());
42        }
43    }

C++ で EPS のサイズを変更し、新しいサイズをミリメートル単位で設定する

次の C++ コードスニペットでは、画像の新しいサイズをミリメートル単位で設定しています。

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2
 3    // The path to the documents directory.
 4    System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
 5    
 6    //Create an input stream for EPS file
 7    {
 8        System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
 9        // Clearing resources under 'using' statement
10        System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
11        // ------------------------------------------
12        
13        try
14        {
15            //Initialize PsDocument object with input stream
16            System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
17            
18            //Get size of EPS image
19            System::Drawing::Size oldSize = doc->ExtractEpsSize();
20            
21            //Create an output stream for resized EPS
22            {
23                System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output_resize_mms.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
24                // Clearing resources under 'using' statement
25                System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
26                // ------------------------------------------
27                
28                try
29                {
30                    //Save EPS to the output stream with new size assigned in millimeters
31                    doc->ResizeEps(outputEpsStream, System::Drawing::SizeF(196.0f, 123.0f), Aspose::Page::Units::Millimeters);
32                }
33                catch(...)
34                {
35                    __dispose_guard_0.SetCurrentException(std::current_exception());
36                }
37            }
38        }
39        catch(...)
40        {
41            __dispose_guard_1.SetCurrentException(std::current_exception());
42        }
43    }

C++ で EPS のサイズを変更し、新しいサイズをパーセントで設定する

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

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2
 3    // The path to the documents directory.
 4    System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
 5    
 6    //Create an input stream for EPS file
 7    {
 8        System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
 9        // Clearing resources under 'using' statement
10        System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
11        // ------------------------------------------
12        
13        try
14        {
15            //Initialize PsDocument object with input stream
16            System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
17            
18            //Get size of EPS image
19            System::Drawing::Size oldSize = doc->ExtractEpsSize();
20            
21            //Create an output stream for resized EPS
22            {
23                System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output_resize_percents.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
24                // Clearing resources under 'using' statement
25                System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
26                // ------------------------------------------
27                
28                try
29                {
30                    //Save EPS to the output stream with new size assigned in percents
31                    doc->ResizeEps(outputEpsStream, System::Drawing::SizeF(200.0f, 200.0f), Aspose::Page::Units::Percents);
32                }
33                catch(...)
34                {
35                    __dispose_guard_0.SetCurrentException(std::current_exception());
36                }
37            }
38        }
39        catch(...)
40        {
41            __dispose_guard_1.SetCurrentException(std::current_exception());
42        }
43    }

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

初期 EPS 画像


初期画像

サイズ変更済み EPS 画像


サイズ変更済み画像

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

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