Redimensionar EPS | Solução API para C++

Visão geral

Este artigo explica como redimensionar o EPS utilizando C++. Aborda os seguintes tópicos.

Descrição do Redimensionamento EPS em C++

Redimensionar a imagem é uma operação que altera uma ou ambas as dimensões da imagem: largura e altura. O conteúdo da imagem permanece o mesmo, mas a imagem em si pode ser dimensionada em função dos novos valores de largura e altura. Se ≥ e ≥ forem aumentados proporcionalmente, a representação da imagem EPS será ampliada; caso contrário, será reduzida. Se ≥ e ≥ forem alterados desproporcionalmente, a representação resultante da imagem EPS será comprimida ou alongada em alguma direção. O volume do ficheiro EPS permanecerá praticamente inalterado, uma vez que a nossa solução não funciona com o conteúdo, mas sim com o cabeçalho e a secção de configuração do ficheiro EPS. Para definir um novo tamanho para a representação de uma imagem EPS, é muitas vezes necessário saber o tamanho atual e escolher as unidades às quais atribuir o novo tamanho. Podem ser pontos (1/72 de polegada), polegadas, milímetros, centímetros e percentagens. Assim sendo, os passos para redimensionar uma imagem EPS em C++ são os seguintes:

  1. Inicialize o objeto PsDocument com um fluxo de entrada contendo o ficheiro EPS.
  2. Extraia o tamanho existente da imagem utilizando o método estático ExtractEpsSize.
  3. Crie um fluxo de saída para o ficheiro EPS resultante.
  4. Redimensione o objeto PsDocument com o novo tamanho nas Unidades selecionadas com o método estático ResizeEps.

Pode verificar a qualidade do Aspose.Page EPS Resize e visualizar os resultados online gratuitamente através do Resize EPS e, em seguida, visualizar o ficheiro EPS resultante com o nosso Visualizador de EPS.


Redimensionar EPS definindo novo tamanho em Pontos em C++

No seguinte excerto de código C++, o novo tamanho da imagem é definido em Pontos (1/72 de polegada):

 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    }

Para Linux, MacOS e outros sistemas operativos que não o Windows, oferecemos a utilização do nosso pacote NuGet Aspose.Page.Drawing. Utiliza o backend Aspose.Drawing em vez da biblioteca de sistema System.Drawing. Assim, importe o namespace Aspose.Page.Drawing em vez do System.Drawing. Nos excertos de código acima e seguintes, será utilizado o Aspose.Page.Drawing.Size em vez do System.Drawing.Size. Os nossos exemplos de código no GitHub contêm todas as substituições necessárias.

Redimensionar o EPS definindo o novo tamanho em polegadas em C++

No seguinte excerto de código C++, o novo tamanho da imagem é definido em polegadas:

 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    }

Redimensionar o EPS definindo o novo tamanho em milímetros em C++

No seguinte excerto de código C++, o novo tamanho da imagem é definido em milímetros:

 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    }

Redimensionar o EPS definindo um novo tamanho em Percentagens em C++

No seguinte excerto de código C++, o novo tamanho da imagem é definido por Percentagens:

 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    }

Consulte Redimensionar EPS em Java e C++.

Imagem EPS inicial


Imagem inicial

Imagem EPS redimensionada


Imagem redimensionada

Avalie o redimensionamento do EPS online na nossa aplicação web Redimensionar EPS. Pode redimensionar o ficheiro EPS e descarregar o resultado em poucos segundos.

Pode descarregar exemplos e ficheiros de dados do GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.