Get frames range from multipages image Introduction
This article explains how to get frames range from multipage images.
There are two APIs to convert an image to another format:
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 the REST API directly from the browser. Description of API parameters is also given there.
cURL Examples
Cloud 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 aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void GetFrameRangeFromImageStorage()
{
string sampleImageFileName = "MultipageFile.djvuf";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
var startFrameId = 17; // Index of the first frame in range
var endFrameId = 23; // Index of the last frame in range
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new GetImageFrameRangeRequest(cloudFileName, startFrameId, endFrameId);
using (Stream frameRange = ImagingApi.GetImageFrameRange(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "DeskewSampleImage_out.tiff")))
{
frameRange.Seek(0, SeekOrigin.Begin);
frameRange.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
public void GetImageFrameRangeFromStorage() throws Exception {
String fileName = "MultipageSampleImage.djvu";
Integer startFrameId = 1; // Index of the first frame in range
Integer endFrameId = 4; // Index of the last frame in range
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
GetImageFrameRangeRequest getImageFrameRangeRequest = new GetImageFrameRangeRequest(getSampleImageFileName(), startFrameId, endFrameId, null, null, null, null, null, null, null, null, folder, storage);
byte[] imageFrame = ImagingApi.getImageFrameRange(getImageFrameRangeRequest);
Path path = Paths.get(OutputFolder, "FrameRange.djvu").toAbsolutePath();
Files.write(path, imageFrame);
}
.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/tree/master/Examples
public void GetFrameRangeFromImageRequestBody()
{
string sampleImageFileName = "MultipageFile.djvu";
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName))
{
var startFrameId = 17; // Index of the first frame in range
var endFrameId = 23; // Index of the last frame in range
string storage = null; // We are using default Cloud Storage
string outPath = null; // Path to updated file (if this is empty, response contains streamed image)
var request = new CreateImageFrameRangeRequest(cloudFileName, startFrameId, endFrameId);
using (Stream frameRange = this.ImagingApi.CreateImageFrameRange(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "MultipageFile_out.djvu")))
{
frameRange.Seek(0, SeekOrigin.Begin);
frameRange.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
public void CreateGrayscaledImageFromRequestBody() throws Exception {
String fileName = "MultipageSampleImage.djvu";
Boolean resizeProportionally = true;
String bkColor = "white";
String storage = null; // We are using default Cloud Storage
String outPath = null; // Path to updated file (if this is empty, response contains streamed image)
byte[] inputStream = Files.readAllBytes(Paths.get(ExampleImagesFolder, getSampleImageFileName()));
CreateImageFrameRangeRequest createImageFrameRangeRequest = new CreateImageFrameRangeRequest(inputStream, startFrameId, endFrameId, null, null, null, null, null, null, null, null, outPath, storage);
byte[] imageFrame = ImagingApi.createImageFrameRange(createImageFrameRangeRequest);
Path path = Paths.get(OutputFolder, "FrameRangeFromRequest.djvu").toAbsolutePath();
Files.write(path, imageFrame);
}