Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active May 21, 2018 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-cloud/af042b4258e2adb36a8c1fa29265f037 to your computer and use it in GitHub Desktop.
Save aspose-cloud/af042b4258e2adb36a8c1fa29265f037 to your computer and use it in GitHub Desktop.
The GIST contains Examples of Aspose.Imaging Cloud APIs.
The GIST contains Examples of Aspose.Imaging Cloud APIs.
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
// optional parameters are base URL, API version, authentication type and debug mode
// default base URL is https://api.aspose.cloud
// default API version is v1.1
// default authentication type is OAuth2.0
// default debug mode is false
var imagingApi = new ImagingApi("yourAppKey", "yourAppSID");
// this GET request converts image files
// optional parameters are output file path, input file folder and Aspose storage name (if you have more than one storage and want to use non-default one)
// if output file path is not set, resulting image is returned in a stream; otherwise, it's saved at the specified path in the storage and null is returned
var getSaveRequest = new GetImageSaveAsRequest("inputImage.jpg", "png", "ResultFolder/resultImage.png", "InputFolder");
// returns null, saves result to storage
imagingApi.GetImageSaveAs(getSaveRequest);
var getStreamRequest = new GetImageSaveAsRequest("inputImage.jpg", "png", null, "InputFolder");
// returns resulting stream
using (Stream resultGetImageStream = imagingApi.GetImageSaveAs(getStreamRequest))
{
// process resulting stream
}
// another option is to use POST request and send image in a stream, if it's not present in your storage
using (FileStream inputImageStream = new FileStream(@"D:\test\localInputImage.jpg", FileMode.Open, FileAccess.Read))
{
var postSaveRequest = new PostImageSaveAsRequest(inputImageStream, "png", "ResultFolder/resultImage.png");
// returns null, saves result to storage
imagingApi.PostImageSaveAs(postSaveRequest);
}
using (FileStream inputImageStream = new FileStream(@"D:\test\localInputImage.jpg", FileMode.Open, FileAccess.Read))
{
var postStreamRequest = new PostImageSaveAsRequest(inputImageStream, "png");
// returns resulting stream
using (Stream resultPostImageStream = imagingApi.PostImageSaveAs(postStreamRequest))
{
// process resulting stream
}
}
// another requests typically follow the same principles
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-java
// optional parameters are base URL, API version, authentication type and debug mode
// default base URL is https://api.aspose.cloud
// default API version is v1.1
// default authentication type is OAuth2.0
// default debug mode is false
ImagingApi imagingApi = new ImagingApi("yourAppKey", "yourAppSID");
// this GET request converts image files
// nullable parameters are output file path, input file folder and Aspose storage name (if you have more than one storage and want to use non-default one)
// if output file path is not set, resulting image is returned in a stream; otherwise, it's saved at the specified path in the storage and null is returned
GetImageSaveAsRequest getSaveRequest = new GetImageSaveAsRequest("inputImage.jpg", "png", "ResultFolder/resultImage.png", "InputFolder", null);
// returns ApiResponse with null response data value, saves result to storage
imagingApi.getImageSaveAs(getSaveRequest);
GetImageSaveAsRequest getStreamRequest = new GetImageSaveAsRequest("inputImage.jpg", "png", null, "InputFolder", null);
// returns ApiResponse with resulting image bytes
ApiResponse apiResponse = imagingApi.getImageSaveAs(getStreamRequest);
// process resulting bytes
byte[] responseData = apiResponse.getResponseData();
// another option is to use POST request and send image in a stream, if it's not present in your storage
InputStream inputStream = null;
byte[] inputBytes = null;
try
{
File inputFile = new File("D:\\test\\localInputImage.jpg");
inputBytes = new byte[(int) inputFile.length()];
inputStream = new FileInputStream(inputFile);
inputStream.read(inputBytes);
}
finally
{
if (inputStream != null)
{
inputStream.close();
}
}
PostImageSaveAsRequest postSaveRequest = new PostImageSaveAsRequest(inputBytes, "png", "ResultFolder/resultImage.png", null);
// returns ApiResponse with null response data value, saves result to storage
imagingApi.postImageSaveAs(postSaveRequest);
PostImageSaveAsRequest postStreamRequest = new PostImageSaveAsRequest(inputBytes, "png", null, null);
// returns ApiResponse with resulting image bytes
apiResponse = imagingApi.postImageSaveAs(postStreamRequest);
// process resulting bytes
responseData = apiResponse.getResponseData();
// another requests typically follow the same principles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment