Update EMF Image Properties Introduction
This article explains how to process an existing EMF image using the given parameters. The API lets you update image properties such as background color, page width and height, and border width and height. You can also export EMF image to one of the following formats: BMP , GIF , WMF , EMF , JPEG , JPEG2000 , PSD , TIFF , WEBP , PNG , SVG and PDF . The default export format is PNG.**
The image can be processed using one of the following two APIs:
The first API expects you to first upload an image to Cloud Storage then pass its name in the API URL. After updating the image parameters, the API returns the updated image in the response. If you would like to save the updated image on the Cloud Storage, you explicitly need to do this as shown in the below examples.
On the other hand, with the second API, you can directly pass the image in the request body. It also lets you save the updated image on the Cloud Storage by specifying the outPath parameter value. However, if you do not specify the value, the response contains a streamed image.
Resource URI
With Swagger UI you can call Aspose.Imaging REST APIs directly from the browser. Description of an API and its parameters are also provided there.
cURL Example
SDKs
Using an SDK (API client) is the quickest way for a developer to speed up the development. An SDK takes care of a lot of low-level details of making requests and handling responses and lets you focus on writing code specific to your particular project. Checkout our GitHub repository for a complete list of Aspose.Imaging Cloud SDKs along with working examples, to get you started in no time. Please check Available SDKs article to learn how to add an SDK to your project.
SDK Examples
.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void ModifyEmfFromStorage()
{
string fileName = "Sample.emf";
// Upload local image to Cloud Storage
using (FileStream localInputImage = File.OpenRead(ImagingBase.PathToDataFiles + fileName))
{
var uploadFileRequest = new UploadFileRequest(fileName, localInputImage);
FilesUploadResult result = this.ImagingApi.UploadFile(uploadFileRequest);
}
string bkColor = "gray";
int pageWidth = 300;
int pageHeigth = 300;
int borderX = 50;
int borderY = 50;
string format = "png";
// Specifies where additional parameters we do not support should be taken from.
// If this is true – they will be taken from default values for standard image,
// if it is false – they will be saved from current image. Default is false.
bool? fromScratch = null;
string folder = null; // Input file is saved at the root of the storage
string storage = null; // As we are using default Cloud Storage
var request = new ModifyEmfRequest(fileName, bkColor, pageWidth, pageHeigth, borderX, borderY,
fromScratch, folder, storage, format);
Stream updatedImage = this.ImagingApi.ModifyEmf(request);
// Save updated image to local storage
using (var fileStream = File.Create(ImagingBase.PathToDataFiles + "SampleEMF_out." + format))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String APP_KEY = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String APP_SID = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String DATA_PATH = "src/main/resources/";
ImagingApi imagingApi = new ImagingApi(APP_KEY, APP_SID);
String fileName = "Sample.emf";
try {
// Upload local image to storage
File inputFile = new File(Main.DATA_PATH + fileName);
FileInputStream localInputImageStream = new FileInputStream(inputFile);
byte[] localInputImage = IOUtils.toByteArray(localInputImageStream);
UploadFileRequest uploadFileRequest = new UploadFileRequest(fileName, localInputImage, null);
FilesUploadResult result = imagingApi.uploadFile(uploadFileRequest);
// Update EMF Image properties
String bkColor = "gray";
Integer pageWidth = 300;
Integer pageHeight = 300;
Integer borderX = 50;
Integer borderY = 50;
String format = "png";
// Specifies where additional parameters we do not support should be taken from.
// If this is true – they will be taken from default values for standard image,
// if it is false – they will be saved from current image. Default is false.
Boolean fromScratch = null;
String outPath = null; // Path to updated file (if this is empty, response contains streamed image)
String folder = null; // Input file is saved at the root of the storage
String storage = null; // As we are using default Cloud Storage
GetImageEmfRequest getImageEmfRequest = new GetImageEmfRequest(fileName, bkColor, pageWidth, pageHeight,
borderX, borderY, fromScratch, outPath, folder, storage, format);
byte[] updatedImage = imagingApi.getImageEmf(getImageEmfRequest);
// Save updated image to local storage
FileOutputStream fos = new FileOutputStream(Main.DATA_PATH + "SampleEMF_out.png");
fos.write(updatedImage);
fos.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void CreateModifiedEmfFromRequestBody()
{
string fileName = "Sample.emf";
using (FileStream inputImageStream = File.OpenRead(ImagingBase.PathToDataFiles + fileName))
{
string bkColor = "gray";
int pageWidth = 300;
int pageHeigth = 300;
int borderX = 50;
int borderY = 50;
string format = "png";
bool? fromScratch = null;
string outPath = null; // Path to updated file (if this is empty, response contains streamed image)
string storage = null; // As we are using default Cloud Storage
var request = new CreateModifiedEmfRequest(inputImageStream, bkColor, pageWidth, pageHeigth,
borderX, borderY, fromScratch, outPath, storage, format);
Stream updatedImage = this.ImagingApi.CreateModifiedEmf(request);
// Save updated image to local storage
using (var fileStream = File.Create(ImagingBase.PathToDataFiles + "SampleEMF_out." + format))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String APP_KEY = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String APP_SID = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String DATA_PATH = "src/main/resources/";
ImagingApi imagingApi = new ImagingApi(APP_KEY, APP_SID);
try {
File file = new File(Main.DATA_PATH + "Sample.emf");
byte[] imageData = Files.readAllBytes(file.toPath());
String bkColor = "gray";
Integer pageWidth = 300;
Integer pageHeight = 300;
Integer borderX = 50;
Integer borderY = 50;
String format = "png";
Boolean fromScratch = null;
String outPath = null; // Path to updated file (if this is empty, response contains streamed image)
String storage = null; // As we are using default Cloud Storage
PostImageEmfRequest postImageEmfRequest = new PostImageEmfRequest(imageData, bkColor, pageWidth, pageHeight,
borderX, borderY, fromScratch, outPath, storage, format);
byte[] updatedImage = imagingApi.postImageEmf(postImageEmfRequest);
// Save updated image to local storage
FileOutputStream fos = new FileOutputStream(Main.DATA_PATH + "SampleEMF_out.png");
fos.write(updatedImage);
fos.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}