Ridimensiona EPS | Soluzione API per C++
Panoramica
Questo articolo spiega come ridimensionare un file EPS usando C++. Tratta i seguenti argomenti.
Descrizione del ridimensionamento EPS in C++
Il ridimensionamento di un’immagine è un’operazione che modifica una o entrambe le dimensioni dell’immagine: larghezza e altezza. Il contenuto dell’immagine rimane invariato, ma l’immagine stessa può essere ridimensionata in base ai nuovi valori di larghezza e altezza. Se larghezza e altezza vengono aumentate proporzionalmente, la rappresentazione dell’immagine EPS verrà ingrandita, altrimenti verrà rimpicciolita. Se larghezza e altezza vengono modificate in modo sproporzionato, la rappresentazione dell’immagine EPS risultante verrà compressa o allungata in una direzione. Il volume del file EPS rimarrà pressoché invariato poiché la nostra soluzione non lavora con il contenuto, ma con l’intestazione e la sezione di configurazione del file EPS. Per impostare una nuova dimensione per la rappresentazione di un’immagine EPS, spesso è necessario conoscerne le dimensioni esistenti e scegliere le unità di misura in cui assegnare la nuova dimensione. Può essere in Punti (1/72 di pollice), Pollici, Millimetri, Centimetri e Percentuali. Quindi, i passaggi per ridimensionare un’immagine EPS in C++ sono i seguenti:
- Inizializzare l’oggetto PsDocument con un flusso di input contenente il file EPS.
- Estrarre le dimensioni esistenti dell’immagine utilizzando il metodo statico ExtractEpsSize.
- Creare un flusso di output per il file EPS risultante. 4. Ridimensiona l’oggetto PsDocument con le nuove dimensioni in Unità selezionate con il metodo statico ResizeEps.
Puoi verificare la qualità del ridimensionamento EPS di Aspose.Page e visualizzare i risultati tramite il Resize EPS online gratuito, quindi visualizzare il file EPS risultante con il nostro Visualizzatore EPS
Ridimensiona EPS impostando una nuova dimensione in Points in C++
Nel seguente frammento di codice C++ la nuova dimensione dell’immagine è impostata in Points (1/72 di pollice):
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 }
Per Linux, macOS e altri sistemi operativi non Windows, offriamo l’utilizzo del nostro pacchetto Nuget Aspose.Page.Drawing. Utilizza il backend Aspose.Drawing anziché la libreria di sistema System.Drawing. Quindi, importate lo spazio dei nomi Aspose.Page.Drawing anziché quello System.Drawing. Nei frammenti di codice sopra e seguenti verrà utilizzato Aspose.Page.Drawing.Size al posto di System.Drawing.Size. I nostri esempi di codice su GitHub contengono tutte le sostituzioni necessarie.
Ridimensionamento di un file EPS impostando una nuova dimensione in pollici in C++
Nel seguente frammento di codice C++ la nuova dimensione dell’immagine viene impostata in pollici:
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 }
Ridimensiona EPS impostando una nuova dimensione in millimetri in C++
Nel seguente frammento di codice C++ la nuova dimensione dell’immagine viene impostata in millimetri:
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 }
Ridimensiona EPS impostando una nuova dimensione in Percentuale in C++
Nel seguente frammento di codice C++ la nuova dimensione dell’immagine viene impostata in Percentuale:
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 }
Immagine iniziale
Immagine ridimensionata
Prova a ridimensionare un file EPS online sulla nostra applicazione web per il ridimensionamento di file EPS. Puoi ridimensionare il file EPS e scaricare il risultato in pochi secondi.
È possibile scaricare esempi e file di dati da GitHub.