|
import com.aspose.imaging.cloud.sdk.model.GaussianBlurFilterProperties;
|
|
import com.aspose.imaging.cloud.sdk.model.requests.FilterEffectImageRequest;
|
|
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
|
|
string ImageFileName = "example_image.dicom";
|
|
string ImagesFolder = "ExampleImages";
|
|
string CloudFolder = "CloudImages";
|
|
string OutputFolder = "Output";
|
|
|
|
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
|
|
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
|
|
ImagingApi api = new ImagingApi(argumentValues.ClientSecret, argumentValues.ClientId, "https://api.aspose.cloud");
|
|
|
|
/**
|
|
* Applies filtering effect to an image from cloud storage.
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public void filterImageFromStorage() throws Exception {
|
|
|
|
// Upload image to cloud storage
|
|
byte[] inputImage = Files.readAllBytes(Paths.get(ImagesFolder, ImageFileName));
|
|
UploadFileRequest request = new UploadFileRequest(Paths.get(CloudFolder, ImageFileName).toString(), image, null);
|
|
FilesUploadResult response = api.uploadFile(request);
|
|
if(response.getErrors() != null && response.getErrors().size() > 0)
|
|
throw new Exception("Uploading errors count: " + response.getErrors().size());
|
|
|
|
String filterType = "GaussianBlur";
|
|
GaussianBlurFilterProperties filterProperties = new GaussianBlurFilterProperties() {{
|
|
setRadius(4);
|
|
setSigma(2.1);
|
|
}};
|
|
String format = "dicom";
|
|
String folder = CloudFolder; // Input file is saved at the desired folder in the storage
|
|
String storage = null; // We are using default Cloud Storage
|
|
|
|
FilterEffectImageRequest request = new FilterEffectImageRequest(ImageFileName, filterType,
|
|
filterProperties, format, folder, storage);
|
|
byte[] updatedImage = api.filterEffectImage(request);
|
|
|
|
// Save the image file to output folder
|
|
String updatedImageName = ImageFileName.substring(0, ImageFileName.lastIndexOf('.') + "dicom";
|
|
Path path = Paths.get(OutputFolder, updatedImageName).toAbsolutePath();
|
|
Files.write(path, updatedImage);
|
|
}
|