Resize EPS | API Solution for C++

Overview

This article explains how to resize EPS using C++. It covers the following topics.

C++ Resize EPS Description

Resizing the image is an operation that changes one of the, or both, dimensions of the image: width and height. The content of the image is left the same, but the image itself can be scaled in dependence of new values of width and height. If with and height are proportionally increased the representation of EPS image will be enlarged, otherwise it will be lessened. If width and height are changed disproportionately the resulting representation of EPS image will be compressed or elangated in some direction. The volume of the EPS file will remain almost unchanged as our solution doesnt’t work with the content but works with the header and the setup section of EPS file. To set up new size for the representation of EPS image often it is necessary to know its existing size and choise the units in which to assign new size. It can be Points (1/72 of inch), Inches, Millimeters, Centimeters and Percents. So the steps for resizing EPS image in C++ follows:

  1. Initialize PsDocument object with an input stream containing EPS file.
  2. Extract existing size of the image using static method ExtractEpsSize.
  3. Create an output stream for resulting EPS file.
  4. Resize PsDocument object with new size in selected Units with static method ResizeEps.

You can check the quality of Aspose.Page EPS Resize and view the results via free online Resize EPS and then view the resulting EPS file with our EPS Viewer


Resize EPS setting new size in Points in C++

In the following C++ code snippet new size of the image is set by Points (1/72 of inch):

 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    }

For Linux, MacOS and other non-Windows operation systems we offer to use our Aspose.Page.Drawing Nuget package. It uses Aspose.Drawing backend instead of System.Drawing system library. So import Aspose.Page.Drawing namespace instead of System.Drawing one. In the above and following code snippets Aspose.Page.Drawing.Size will be used instead of System.Drawing.Size. Our code examples on GitHub contain all the necessary substitutions.

Resize EPS setting new size in Inches in C++

In the following C++ code snippet new size of the image is set by Inches:

 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    }

Resize EPS setting new size in Millimeters in C++

In the following C++ code snippet new size of the image is set by Millimeters:

 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    }

Resize EPS setting new size in Percents in C++

In the following C++ code snippet new size of the image is set by Percents:

 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    }

See Resize EPS in Java and C++.

Initial EPS Image


Initial image

Resized EPS Image


Resized image

Evaluate resizing EPS online on our Resize EPS web application. You can resize EPS file and dowload result in a few seconds.

You can download examples and data files from GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.