Image Effect Creator Licensing Plugin
Utilize the Image Effect Creator Licensing Plugin to access a wide array of image enhancements and filters. With this plugin, you can smooth images using filters such as GaussianBlur, MedianFilter, BilateralSmoothing or MotionWeiner filter. Additionally, you have the ability to adjust image parameters like brightness, contrast, and color gamma, and apply effects such as dithering, binarization, and grayscale. The provided Java example showcases the application of these filters and effects to images from supported file formats list using the RasterImage class. Before using the filters, remember to obtain a Metered license by providing your public and private keys using the `setMeteredKey()` method.
import com.aspose.imaging.DitheringMethod; | |
import com.aspose.imaging.Image; | |
import com.aspose.imaging.Metered; | |
import com.aspose.imaging.RasterImage; | |
import com.aspose.imaging.dithering.DitheringMode; | |
import com.aspose.imaging.imagefilters.filteroptions.*; | |
import java.io.File; | |
import java.util.function.Function; | |
//------------------------------------------------------------------------------ | |
// Image effect plug-in license use examples | |
//------------------------------------------------------------------------------ | |
/** | |
* <p> | |
* Applies the filter. | |
* </p> | |
* @param inputFileName The input file name. | |
* @param outputFileName The output file name. | |
* @param options The options. | |
*/ | |
void applyFilter(String inputFileName, String outputFileName, FilterOptionsBase options) | |
{ | |
try (Image image = Image.load(inputFileName)) | |
{ | |
if (image instanceof RasterImage) | |
{ | |
RasterImage rasterImage = (RasterImage) image; | |
rasterImage.filter(image.getBounds(), options); | |
image.save(outputFileName); | |
} | |
} | |
} | |
void applyImageEffect(String inputFileName, String outputFileName, Function<Image, Image> doEffect) | |
{ | |
try (RasterImage image = (RasterImage)Image.load(inputFileName)) | |
{ | |
Image outImage = doEffect.apply(image); | |
outImage.save(outputFileName); | |
} | |
} | |
Image doDithering(Image image) | |
{ | |
if (image instanceof RasterImage) | |
{ | |
RasterImage raster = (RasterImage) image; | |
DitheringMode dithering = new DitheringMode(); | |
dithering.setBits(1); | |
dithering.setMethod(DitheringMethod.ThresholdDithering); | |
raster.dither(dithering.getMethod(), dithering.getBits()); | |
return raster; | |
} | |
return null; | |
} | |
/** | |
* Binarization test. | |
*/ | |
Image doBinarizeBradley(Image image) | |
{ | |
if (image instanceof RasterImage) | |
{ | |
RasterImage rasterImage = (RasterImage) image; | |
int threshold = -2; | |
if (threshold != -1 && threshold != -2) | |
{ | |
byte b = (byte)threshold; | |
rasterImage.binarizeFixed(b); | |
} | |
else if (threshold == -2) | |
{ | |
rasterImage.binarizeBradley(threshold); | |
} | |
else | |
{ | |
rasterImage.binarizeOtsu(); | |
} | |
return rasterImage; | |
} | |
throw new AssertionError("Image should be the raster image"); | |
} | |
/** | |
* Grayscale test. | |
*/ | |
Image doGrayscale(Image image) | |
{ | |
if (image instanceof RasterImage) | |
{ | |
RasterImage rasterImage = (RasterImage) image; | |
rasterImage.grayscale(); | |
return rasterImage; | |
} | |
throw new AssertionError("Image should be the raster image"); | |
} | |
/** | |
* Brightness test. | |
*/ | |
Image doBrightness(Image image) | |
{ | |
if (image instanceof RasterImage) | |
{ | |
RasterImage rasterImage = (RasterImage) image; | |
int brightness = 70; | |
rasterImage.adjustBrightness(brightness); | |
return rasterImage; | |
} | |
throw new AssertionError("Image should be the raster image"); | |
} | |
/** | |
* Contrast test. | |
*/ | |
Image doContrast(Image image) | |
{ | |
if (image instanceof RasterImage) | |
{ | |
RasterImage rasterImage = (RasterImage) image; | |
int contrast = 80; | |
rasterImage.adjustContrast(contrast); | |
return rasterImage; | |
} | |
throw new AssertionError("Image should be the raster image"); | |
} | |
/** | |
* Gamma test. | |
*/ | |
Image doGamma(Image image) | |
{ | |
if (image instanceof RasterImage) | |
{ | |
RasterImage rasterImage = (RasterImage) image; | |
float gamma1 = 3; | |
rasterImage.adjustGamma(gamma1); | |
return rasterImage; | |
} | |
throw new AssertionError("Image should be the raster image"); | |
} | |
// Valid image effect license use example | |
Metered license = new Metered(); | |
// Only metered plug-in license is supported | |
license.setMeteredKey("<your public key>", "<your private key>"); | |
// get path of the input data | |
String templatesFolder = System.getenv("DATA_PATH"); | |
if (templatesFolder == null) | |
{ | |
templatesFolder = "c:\\Users\\USER\\Downloads\\templates\\"; | |
} | |
// get output path | |
String outputDirectory = System.getenv("OUT_PATH"); | |
if (outputDirectory == null) | |
{ | |
outputDirectory = templatesFolder; | |
} | |
String inputFileName = templatesFolder + File.separator + "template.png"; | |
applyFilter(inputFileName, outputDirectory + "licensed_gauss_effect.png", | |
new GaussWienerFilterOptions(13, 2) | |
{{ | |
setBrightness(1); | |
}} | |
); | |
applyFilter(inputFileName, outputDirectory + "licensed_bilateral_smoothing.png", | |
new BilateralSmoothingFilterOptions()); | |
applyFilter(inputFileName, outputDirectory + "licensed_gauss_wiener.png", | |
new GaussWienerFilterOptions(5, 1.5) | |
{{ | |
setBrightness(1); | |
setSnr(0.003); | |
}} | |
); | |
applyFilter(inputFileName, outputDirectory + "licensed_motion_wiener.png", | |
new MotionWienerFilterOptions(10, 1, 0) | |
{{ | |
setBrightness(1); | |
setSnr(0.007); | |
}} | |
); | |
applyFilter(templatesFolder + "template.png", outputDirectory + "licensed_gauss_blur.png", | |
new GaussianBlurFilterOptions(5, 4)); | |
applyFilter(inputFileName, outputDirectory + "licensed_gauss_wienere_grayscale.png", | |
new GaussWienerFilterOptions(6, 3) {{ setGrayscale(true); }} | |
); | |
applyFilter(inputFileName, outputDirectory + "licensed_median_effect.png", | |
new MedianFilterOptions(4) | |
); | |
applyImageEffect(inputFileName, outputDirectory + "licensed_dithering.png", this::doDithering); | |
applyImageEffect(inputFileName, outputDirectory + "licensed_binarization.png", this::doBinarizeBradley); | |
applyImageEffect(inputFileName, outputDirectory + "licensed_grayscale.png", this::doGrayscale); | |
applyImageEffect(inputFileName, outputDirectory + "licensed_brightness_change.png", this::doBrightness); | |
applyImageEffect(inputFileName, outputDirectory + "licensed_contrast_change.png", this::doContrast); | |
applyImageEffect(inputFileName, outputDirectory + "licensed_gamma_change.png", this::doGamma); |
Discover the multitude of features and capabilities of image effects available on our Aspose.Imaging Photo Filter free online application website.