Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.Imaging-Cloud-Java
This Gist repository contains code snippet related to Aspose.Imaging.Cloud SDK for Java
public void BoundsAnImageInCloud() throws Exception {
String fileName = "object_detection_example.jpg";
String method = "ssd";
int threshold = 50;
Boolean includeLabel = true;
Boolean includeScore = true;
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
GetObjectBoundsRequest request = new GetObjectBoundsRequest(getSampleImageFileName(), method, threshold, includeLabel, includeScore, folder, storage);
DetectedObjectList detectedObjectsList = ImagingApi.getObjectBounds(request);
}
public void BoundsAnImageInRequestBody() throws Exception {
String fileName = "object_detection_example.jpg";
String method = "ssd";
int threshold = 50;
Boolean includeLabel = true;
Boolean includeScore = true;
String outPath = null;
String storage = null; // We are using default Cloud Storage
byte[] inputStream = Files.readAllBytes(Paths.get(ExampleImagesFolder, getSampleImageFileName()));
CreateObjectBoundsRequest request = new CreateObjectBoundsRequest(inputStream, method, threshold, includeLabel, includeScore, outPath, storage);
DetectedObjectList detectedObjectsList = ImagingApi.createObjectBounds(request);
}
public void DeskewAnImageInCloud() throws Exception {
String fileName = "DeskewSampleImage.tif";
Boolean resizeProportionally = true;
String bkColor = "white";
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
DeskewImageRequest request = new DeskewImageRequest(getSampleImageFileName(), resizeProportionally, bkColor, folder, storage);
byte[] updatedImage = ImagingApi.deskewImage(request);
Path path = Paths.get(OutputFolder, "DeskewSampleImage_out.tif").toAbsolutePath();
Files.write(path, updatedImage);
}
public void DeskewAnImageInRequestBody() throws Exception {
String fileName = "DeskewSampleImage.tif";
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()));
CreateDeskewedImageRequest request = new CreateDeskewedImageRequest(inputStream, resizeProportionally, bkColor, outPath, storage);
byte[] updatedImage = ImagingApi.createDeskewedImage(request);
Path path = Paths.get(OutputFolder, "DeskewSampleImage_out.tif").toAbsolutePath();
Files.write(path, updatedImage);
}
public void DetectUndesiredObjects() throws Exception {
System.out.println("Detect objects on an image that is passed in a request stream");
String method = "ssd";
int threshold = 50;
Boolean includeLabel = true;
Boolean includeScore = true;
String outPath = null;
String storage = null; // We are using default Cloud Storage
byte[] inputStream = Files.readAllBytes(Paths.get(ExampleImagesFolder, getSampleImageFileName()));
CreateObjectBoundsRequest request = new CreateObjectBoundsRequest(inputStream, method, threshold, includeLabel, includeScore, outPath, storage);
System.out.println(String.format("Call CreateObjectBoundsRequest with params: method: %s, threshold: %s, includeLabel: %s, includeScore: %s", method, threshold, includeLabel, includeScore));
DetectedObjectList detectedObjectsList = ImagingApi.createObjectBounds(request);
for (DetectedObject obj : detectedObjectsList.getDetectedObjects())
{
if(obj.getLabel() == "dog") {
Alert();
}
}
}
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);
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
String fileName = "WaterMark.bmp";
try {
// Upload local image to Cloud 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);
// Output formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG, SVG and PDF
String format = "pdf";
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; // Cloud Storage name
ConvertImageRequest request = new ConvertImageRequest(fileName, format, outPath, folder, storage);
byte[] exportedImage = imagingApi.convertImage(request);
// Save exported image to local storage
FileOutputStream fos = new FileOutputStream(Main.DATA_PATH + "Watermark_out.pdf");
fos.write(exportedImage);
fos.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
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 {
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
File file = new File(Main.DATA_PATH + "WaterMark.bmp");
byte[] imageData = Files.readAllBytes(file.toPath());
// Output formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG, SVG and PDF
String format = "pdf";
String outPath = null; // Path to updated file (if this is empty, response contains streamed image)
String storage = null; // Cloud Storage name
CreateConvertedImageRequest request = new CreateConvertedImageRequest(imageData, format, outPath, storage);
byte[] exportedImage = imagingApi.createConvertedImage(request);
// Save exported image to local storage
FileOutputStream fos = new FileOutputStream(Main.DATA_PATH + "Watermark_out.pdf");
fos.write(exportedImage);
fos.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
public void GrayscaleImageFromStorage() throws Exception {
String fileName = "FilterEffectSampleImage.psd";
byte[] inputImage = Files.readAllBytes(Paths.get(ExampleImagesFolder, fileName));
UploadFileRequest request = new UploadFileRequest(Paths.get(CloudPath, fileName).toString(), image, null);
FilesUploadResult response = ImagingApi.uploadFile(request);
String filterType = "GaussianBlur";
GaussianBlurFilterProperties filterProperties = new GaussianBlurFilterProperties() {{
setRadius(4);
setSigma(2.1);
}};
String format = "bmp";
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
FilterEffectImageRequest request = new FilterEffectImageRequest(getSampleImageFileName(), filterType,
filterProperties, format, folder, storage);
byte[] updatedImage = ImagingApi.filterEffectImage(request);
Path path = Paths.get(OutputFolder, "GrayscaleSampleImage_out.bmp").toAbsolutePath();
Files.write(path, updatedImage);
}
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);
}
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);
}
public void GrayscaleImageFromStorage() throws Exception {
String fileName = "GrayscaleSampleImage.bmp";
byte[] inputImage = Files.readAllBytes(Paths.get(ExampleImagesFolder, fileName));
UploadFileRequest request = new UploadFileRequest(Paths.get(CloudPath, fileName).toString(), image, null);
FilesUploadResult response = ImagingApi.uploadFile(request);
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
GrayscaleImageRequest request = new GrayscaleImageRequest(getSampleImageFileName(), folder, storage);
byte[] updatedImage = ImagingApi.grayscaleImage(request);
Path path = Paths.get(OutputFolder, "GrayscaleSampleImage_out.bmp").toAbsolutePath();
Files.write(path, updatedImage);
}
public void CreateGrayscaledImageFromRequestBody() throws Exception {
String fileName = "GrayscaleSampleImage.bmp";
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, fileName));
CreateGrayscaledImageRequest request = new CreateGrayscaledImageRequest(inputStream, outPath, storage);
byte[] updatedImage = ImagingApi.createGrayscaledImage(request);
byte[] updatedImage = ImagingApi.grayscaleImage(request);
Path path = Paths.get(OutputFolder, "GrayscaleSampleImage_out.bmp").toAbsolutePath();
Files.write(path, updatedImage);
}
public void VisualBoundsAnImageInCloud() throws Exception {
String fileName = "object_detection_example.jpg";
String method = "ssd";
int threshold = 50;
Boolean includeLabel = true;
Boolean includeScore = true;
String color = "blue";
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
GetVisualObjectBoundsRequest request = new GetVisualObjectBoundsRequest(getSampleImageFileName(), method, threshold, includeLabel, includeScore, color, folder, storage);
byte[] resultImage = ImagingApi.getVisualObjectBounds(request);
Path path = Paths.get(OutputFolder, "object_detection_example_out.jpg").toAbsolutePath();
Files.write(path, resultImage);
}
public void VisualBoundsAnImageInRequestBody() throws Exception {
String fileName = "object_detection_example.jpg";
String method = "ssd";
int threshold = 50;
Boolean includeLabel = true;
Boolean includeScore = true;
String color = null;
String outPath = null;
String storage = null; // We are using default Cloud Storage
byte[] inputStream = Files.readAllBytes(Paths.get(ExampleImagesFolder, getSampleImageFileName()));
CreateVisualObjectBoundsRequest request = new CreateVisualObjectBoundsRequest(inputStream, method, threshold, includeLabel, includeScore, color, outPath, storage);
byte[] resultImage = ImagingApi.createVisualObjectBounds(request);
Path path = Paths.get(OutputFolder, "object_detection_example_out.jpg").toAbsolutePath();
Files.write(path, resultImage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.