Redimensionar EPS | Solução API .NET
Visão geral
Este artigo explica como redimensionar o EPS utilizando C#. Aborda os seguintes tópicos.
- Descrição de Redimensionamento EPS em C#
- Redimensionar EPS em C# definindo o novo tamanho em Pontos
- Redimensionar EPS em C# definindo o novo tamanho em Polegadas
- Redimensionar EPS em C# definindo o novo tamanho em Milímetros
- Redimensionar EPS em C# definindo o novo tamanho em Percentagens
Descrição do Redimensionamento EPS em C#
Redimensionar a imagem é uma operação que altera uma das dimensões da imagem, ou ambas: a largura e a altura. O conteúdo da imagem permanece o mesmo, mas a imagem em si pode ser redimensionada dependendo dos novos valores de largura e altura. Se a largura e a altura forem aumentadas proporcionalmente, a representação da imagem EPS será ampliada; caso contrário, será reduzida. Se a largura e a altura forem alteradas de forma desproporcional, 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 para o atribuir. Pode ser em pontos (1/72 de polegada), polegadas, milímetros, centímetros e percentagens. Assim, os passos para redimensionar uma imagem EPS em C# são os seguintes:
Inicialize o objeto PsDocument com um fluxo de entrada contendo o ficheiro EPS.
Extraia o tamanho existente da imagem utilizando o método estático ExtractEpsSize.
Crie um fluxo de saída para o ficheiro EPS resultante.
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
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-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6
7//Initialize PsDocument object with EPS file
8PsDocument doc = new PsDocument(dataDir + "input.eps");
9
10//Get size of EPS image
11Size oldSize = doc.ExtractEpsSize();
12
13//Create an output stream for resized EPS
14using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_inches.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
15{
16 //Save EPS to the output stream with new size assigned in inches
17 doc.ResizeEps(outputEpsStream, new SizeF(oldSize.Width * 2, oldSize.Height * 2), Units.Points);
18}
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-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6 //Create an input stream for EPS file
7using (Stream inputEpsStream = new System.IO.FileStream(dataDir + "input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read))
8{
9 //Initialize PsDocument object with input stream
10 PsDocument doc = new PsDocument(inputEpsStream);
11
12 //Get size of EPS image
13 Size oldSize = doc.ExtractEpsSize();
14
15 //Create an output stream for resized EPS
16 using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_inches.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
17 {
18 //Save EPS to the output stream with new size assigned in inches
19 doc.ResizeEps(outputEpsStream, new SizeF(5.791f, 3.625f), Units.Inches);
20 }
21}
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-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6 //Create an input stream for EPS file
7using (Stream inputEpsStream = new System.IO.FileStream(dataDir + "input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read))
8{
9 //Initialize PsDocument object with input stream
10 PsDocument doc = new PsDocument(inputEpsStream);
11
12 //Get size of EPS image
13 Size oldSize = doc.ExtractEpsSize();
14
15 //Create an output stream for resized EPS
16 using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_mms.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
17 {
18 //Save EPS to the output stream with new size assigned in millimeters
19 doc.ResizeEps(outputEpsStream, new SizeF(196, 123), Units.Millimeters);
20 }
21}
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-.NET
2
3// The path to the documents directory.
4string dataDir = GetDataDir();
5
6 //Create an input stream for EPS file
7using (Stream inputEpsStream = new System.IO.FileStream(dataDir + "input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read))
8{
9 //Initialize PsDocument object with input stream
10 PsDocument doc = new PsDocument(inputEpsStream);
11
12 //Get size of EPS image
13 Size oldSize = doc.ExtractEpsSize();
14
15 //Create an output stream for resized EPS
16 using (Stream outputEpsStream = new System.IO.FileStream(dataDir + "output_resize_mms.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
17 {
18 //Save EPS to the output stream with new size assigned in percents
19 doc.ResizeEps(outputEpsStream, new SizeF(200, 200), Units.Percents);
20 }
21}
Initial 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.
Pode descarregar exemplos e ficheiros de dados do GitHub.