Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.Imaging for Java
Gist for Aspose.Imaging for Java
// The path to the documents directory.
String baseFolder = Utils.getSharedDataDir(SupportOfCDR.class) + "CDR/";
String inputFileName = baseFolder + "test.cdr";
long expectedFileFormat = FileFormat.Cdr;
long realFileFormat = Image.getFileFormat(inputFileName);
Assert.assertEquals(expectedFileFormat, realFileFormat, "File format is incorrect!");
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CMXToPNGConversion.class) + "CMX/";
// Example of exporting the entire document page
String[] fileNames = new String[] {
"Rectangle.cmx",
"Rectangle+Fill.cmx",
"Ellipse.cmx",
"Ellipse+fill.cmx",
"brushes.cmx",
"outlines.cmx",
"order.cmx",
"many_images.cmx",
};
for (String fileName: fileNames) {
Image image = Image.load(dataDir + fileName);
try {
CmxRasterizationOptions cmxRasterizationOptions = new CmxRasterizationOptions();
cmxRasterizationOptions.setPositioning(PositioningTypes.DefinedByDocument);
cmxRasterizationOptions.setSmoothingMode(SmoothingMode.AntiAlias);
PngOptions options = new PngOptions();
options.setVectorRasterizationOptions(cmxRasterizationOptions);
image.save(dataDir + fileName + ".docpage.png", options);
} finally {
image.close();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
TiffImage image = (TiffImage) com.aspose.imaging.Image.load(dataDir + "sample.tif");
image.alignResolutions();
// Save the results to output path.
image.save(dataDir + "AligHorizontalAndVeticalResolutions_out.tiff");
int framesCount = image.getFrames().length;
for (int i = 0; i < framesCount; i++) {
TiffFrame frame = image.getFrames()[i];
// All resolutions after aligment must be equal
System.out.println("Horizontal and vertical resolutions are equal:"
+ ((int) frame.getVerticalResolution() == (int) frame.getHorizontalResolution()));
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir + "aspose-logo.jpg");
// Convert the image into RasterImage.
RasterImage rasterImage = (RasterImage) image;
if (rasterImage == null) {
return;
}
// Get Bounds[rectangle] of image.
com.aspose.imaging.Rectangle rect = image.getBounds();
// Create an instance of BilateralSmoothingFilterOptions class with size
// parameter.
com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions bilateralOptions = new com.aspose.imaging.imagefilters.filteroptions.BilateralSmoothingFilterOptions(
3);
// Create an instance of SharpenFilterOptions class.
com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions sharpenOptions = new com.aspose.imaging.imagefilters.filteroptions.SharpenFilterOptions();
// Supply the filters to raster image.
rasterImage.filter(rect, bilateralOptions);
rasterImage.filter(rect, sharpenOptions);
// Adjust the contrast accordingly.
rasterImage.adjustContrast(-10);
// Set brightness using Binarize Bradley
rasterImage.binarizeBradley(80);
// Save the results to output path.
rasterImage.save(dataDir + "a1_out.jpg");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir + "aspose-logo.gif");
// caste the image into RasterImage
RasterImage rasterImage = (RasterImage) image;
if (rasterImage == null) {
return;
}
// Create an instance of GaussWienerFilterOptions class and set the
// radius size and smooth value.
GaussWienerFilterOptions options = new GaussWienerFilterOptions(12, 3);
options.setGrayscale(true);
// apply MedianFilterOptions filter to RasterImage object.
rasterImage.filter(image.getBounds(), options);
// Save the resultant image
image.save(dataDir + "ApplyGaussWienerFilter_out.gif");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir + "aspose-logo.gif");
// caste the image into RasterImage
RasterImage rasterImage = (RasterImage) image;
if (rasterImage == null) {
return;
}
// Create an instance of GaussWienerFilterOptions class and set the
// radius size and smooth value.
GaussWienerFilterOptions options = new GaussWienerFilterOptions(5, 1.5);
options.setBrightness(1);
// apply MedianFilterOptions filter to RasterImage object.
rasterImage.filter(image.getBounds(), options);
// Save the resultant image
image.save(dataDir + "ApplyGaussWienerFilter_out.gif");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Load the noisy image
Image image = Image.load(dataDir + "aspose-logo.gif");
// caste the image into RasterImage
RasterImage rasterImage = (RasterImage) image;
if (rasterImage == null)
{
return;
}
// Create an instance of MedianFilterOptions class and set the size.
MedianFilterOptions options = new MedianFilterOptions(4);
// Apply MedianFilterOptions filter to RasterImage object.
rasterImage.filter(image.getBounds(), options);
// Save the resultant image
image.save(dataDir + "median_test_denoise_out.gif");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir + "aspose-logo.gif");
// caste the image into RasterImage
RasterImage rasterImage = (RasterImage) image;
if (rasterImage == null) {
return;
}
// Create an instance of MotionWienerFilterOptions class and set the
// length, smooth value and angle.
MotionWienerFilterOptions options = new MotionWienerFilterOptions(50, 9, 90);
options.setGrayscale(true);
// apply MedianFilterOptions filter to RasterImage object.
rasterImage.filter(image.getBounds(), options);
// Save the resultant image
image.save(dataDir + "ApplyingMotionWienerFilter_out.gif");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Load an image in an instance of Image
Image image = Image.load(dataDir + "aspose-logo.jpg");
// Cast the image to RasterCachedImage
RasterCachedImage rasterCachedImage = (RasterCachedImage) image;
// Check if image is cached
if (!rasterCachedImage.isCached()) {
// Cache image if not already cached
rasterCachedImage.cacheData();
}
// Binarize image with pre defined fixed threshold
rasterCachedImage.binarizeFixed((byte) 100);
// Save the resultant image
rasterCachedImage.save(dataDir + "BinarizationWithFixedThreshold_out.jpg");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Load an image in an instance of Image
Image image = Image.load(dataDir + "aspose-logo.jpg");
// Cast the image to RasterCachedImage
RasterCachedImage rasterCachedImage = (RasterCachedImage) image;
// Check if image is cached
if (!rasterCachedImage.isCached()) {
// Cache image if not already cached
rasterCachedImage.cacheData();
}
// Binarize image with Otsu Thresholding
rasterCachedImage.binarizeOtsu();
// Save the resultant image
rasterCachedImage.save(dataDir + "BinarizationWithOtsuThreshold_out.jpg");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String dataDir = Utils.getSharedDataDir(BMPToPDF.class) + "ConvertingImages/";
String outputFile = "result.pdf";
BmpImage image = (BmpImage)Image.load(dataDir);
try
{
PdfOptions exportOptions = new PdfOptions();
exportOptions.setPdfDocumentInfo(new PdfDocumentInfo());
image.save(outputFile, exportOptions);
}
finally
{
image.close();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Load a GIF image
Image objImage = Image.load(dataDir + "aspose-logo.gif");
// Convert the image to GIF image
GifImage gif = (GifImage) objImage;
// iterate through arry of blocks in the GIF image
for (int i = 0; i < gif.getBlocks().length; i++) {
// convert block to GifFrameBlock class instance
GifFrameBlock gifBlock = ((GifFrameBlock) (gif.getBlocks()[i]));
// Check if gif block is then ignore it
if (gifBlock == null) {
continue;
}
// Create an instance of TIFF Option class
TiffOptions objTiff = new TiffOptions(TiffExpectedFormat.Default);
// Save the GIFF block as TIFF image
gifBlock.save(dataDir + "asposelogo" + i + "_out.tif", objTiff);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String[] paths = new String[]
{
"C:\\test\\butterfly.gif",
"C:\\test\\33715-cmyk.jpeg",
"C:\\test\\3.JPG",
"C:\\test\\test.j2k",
"C:\\test\\Rings.png",
"C:\\test\\3layers_maximized_comp.psd",
"C:\\test\\img4.TIF",
"C:\\test\\Lossy5.webp"
};
for (String path : paths)
{
String destPath = path + ".svg";
Image image = Image.load(path);
try
{
SvgOptions svgOptions = new SvgOptions();
SvgRasterizationOptions svgRasterizationOptions = new SvgRasterizationOptions();
svgRasterizationOptions.setPageWidth(image.getWidth());
svgRasterizationOptions.setPageHeight(image.getHeight());
svgOptions.setVectorRasterizationOptions(svgRasterizationOptions);
image.save(destPath, svgOptions);
}
finally
{
image.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Load the image
SvgImage image = (SvgImage)Image.load(dataDir + "aspose-logo.Svg");
// Create an instance of PNG options
PngOptions pngOptions = new PngOptions();
// Save the results to disk
image.save(dataDir + "ConvertingSVGToRasterImages_out.png", pngOptions);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir+"mysvg.svg");
try
{
image.save(dataDir+"yoursvg.svg");
}
finally
{
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String dataDir = Utils.getSharedDataDir(ExpandandCropImages.class) + "ConvertingImages/";
RasterImage rasterImage = (RasterImage) Image.load(dataDir + "aspose-logo.jpg");
// setting for image data to be cashed
rasterImage.cacheData();
// Create an instance of Rectangle class and define X,Y and Width, height of the rectangle.
Rectangle destRect = new Rectangle(200, 200, 300, 300);
// Save output image by passing output file name, image options and rectangle object.
rasterImage.save(dataDir + "ExpandandCropImages_out.jpg", new JpegOptions(), destRect);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Create temporary image.
java.io.File tmp = java.io.File.createTempFile("image", "tes");
// Delete the file. This statement should execute to make it sure that resource is properly disposed off.
tmp.deleteOnExit();
// Path & name of existing image.
String imageDataPath = tmp.getAbsolutePath();
// Create the stream of the existing image file.
java.io.InputStream fileStream = new java.io.FileInputStream(tmp);
try
{
// Create an instance of BMP image option class.
com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions();
try
{
bmpOptions.setBitsPerPixel(32);
// Set the source property of the imaging option class object.
bmpOptions.setSource(new com.aspose.imaging.sources.StreamSource(fileStream));
// Do processing. Following is the sample processing on the image. Un-comment to use it.
// com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.create(bmpOptions, 10, 10);
// try
// {
// com.aspose.imaging.Color[] pixels = new com.aspose.imaging.Color[4];
// for (int i = 0; i < 4; ++i)
// {
// pixels[i] = com.aspose.imaging.Color.fromArgb(40, 30, 20, 10);
// }
// image.savePixels(new com.aspose.imaging.Rectangle(0, 0, 2, 2), pixels);
// image.save(imageDataPath);
//}
//finally
//{
// This statement is in the final block because in any case this statement should execute to make it sure that resource is properly disposed off.
// image.dispose();
//}
}
finally
{
// This statement is in the final block because in any case this statement should execute to make it sure that resource is properly disposed off.
bmpOptions.dispose();
}
}
finally
{
// This statement is in the final block because in any case this statement should execute to make it sure that resource is properly disposed off.
fileStream.close();
fileStream = null;
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String dataDir = Utils.getSharedDataDir(Grayscaling.class) + "ConvertingImages/";
Image image = Image.load(dataDir + "aspose-logo.jpg");
// Cast the image to RasterCachedImage
RasterCachedImage rasterCachedImage = (RasterCachedImage) image;
// Check if image is cached
if (!rasterCachedImage.isCached()) {
// Cache image if not already cached
rasterCachedImage.cacheData();
}
// Transform image to its grayscale representation
rasterCachedImage.grayscale();
// Save the resultant image
rasterCachedImage.save(dataDir + "Grayscaling_out.jpg");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String dataDir = Utils.getSharedDataDir(PNGToPDF.class) + "ConvertingImages/";
PngImage pngImage = (PngImage) Image.load(dataDir + "aspose_logo.png");
try
{
PdfOptions exportOptions = new PdfOptions();
exportOptions.setPdfDocumentInfo(new PdfDocumentInfo());
pngImage.save("multipage_specificColor_.djvu4_ethalon.pdf", exportOptions);
}
finally
{
pngImage.close();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir);
try
{
PsdImage psdImage = (PsdImage)image;
PdfOptions exportOptions = new PdfOptions();
exportOptions.setPdfDocumentInfo(new com.aspose.imaging.fileformats.pdf.PdfDocumentInfo());
psdImage.save(dataDir+"result.pdf", exportOptions);
}
finally
{
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String dataDir = Utils.getSharedDataDir(RasterImageToPDF.class) + "ConvertingImages/";
String destFilePath = "transparent_orig.gif.pdf";
Image image = Image.load(dataDir);
try
{
image.save(destFilePath, new PdfOptions());
}
finally
{
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Specify the size of image by defining a Rectangle
Rectangle rect = new Rectangle(0, 0, 100, 200);
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRgb);
tiffOptions.setPhotometric(TiffPhotometrics.MinIsBlack);
// create the brand new image just for sample purposes
TiffImage image = new TiffImage(new TiffFrame(tiffOptions, rect.getWidth(), rect.getHeight()));
// create an instance of XMP-Header
XmpHeaderPi xmpHeader = new XmpHeaderPi();
xmpHeader.setGuid(dataDir);
// create an instance of Xmp-TrailerPi
XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);
// create an instance of XMPmeta class to set different attributes
XmpMeta xmpMeta = new XmpMeta();
xmpMeta.addAttribute("Author", "Mr Smith");
xmpMeta.addAttribute("Description", "The fake metadata value");
// create an instance of XmpPacketWrapper that contains all metadata
XmpPacketWrapper xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
// create an instacne of Photoshop package and set photoshop attributes
PhotoshopPackage photoshopPackage = new PhotoshopPackage();
photoshopPackage.setCity("London");
photoshopPackage.setCountry("England");
photoshopPackage.setColorMode(ColorMode.Rgb);
// add photoshop package into XMP metadata
xmpData.addPackage(photoshopPackage);
// create an instacne of DublinCore package and set dublinCore attributes
DublinCorePackage dublinCorePackage = new DublinCorePackage();
dublinCorePackage.setAuthor("Charles Bukowski");
dublinCorePackage.setTitle("Confessions of a Man Insane Enough to Live With the Beasts");
dublinCorePackage.addValue("dc:movie", "Barfly");
// add dublinCore Package into XMP metadata
xmpData.addPackage(dublinCorePackage);
MemoryStream ms = new MemoryStream();
// update XMP metadata into image
image.setXmpData(xmpData);
// Save image on the disk or in memory stream
image.save();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String sourceFilePath = "testTileDeflate.tif";
String outputFilePath = "testTileDeflate Cmyk.tif";
TiffOptions options = new TiffOptions(TiffExpectedFormat.TiffLzwCmyk);
Image image = Image.load(sourceFilePath);
{
image.save(outputFilePath, options);
}
{
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir+"test.bmp");
try
{
image.save("test.bmp.png", new PngOptions());
}
finally
{
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String[] files = new String[] {"example.odg", "example1.odg"};
String folder = "C:\\Temp\\";
final MetafileRasterizationOptions rasterizationOptions = new MetafileRasterizationOptions();
for (String file : files)
{
String fileName = folder + file;
Image image = Image.load(fileName);
try
{
rasterizationOptions.setPageSize(new SizeF(image.getWidth(), image.getHeight()));
String outFileName = fileName.replace(".odg", ".png");
image.save(outFileName,
new PngOptions()
{{
setVectorRasterizationOptions(rasterizationOptions);
}});
outFileName = fileName.replace(".odg", ".pdf");
image.save(outFileName,
new PdfOptions()
{{
setVectorRasterizationOptions(rasterizationOptions);
}});
}
finally
{
image.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
public static void main(String... args) throws Exception {
String dataDir = Utils.getSharedDataDir(SVGToEMFConversion.class) + "ConvertingImages/";
String[] testFiles = new String[]
{
"input.svg",
"juanmontoya_lingerie.svg",
"rg1024_green_grapes.svg",
"sample_car.svg",
"tommek_Car.svg"
};
String basePath = dataDir+"IMAGINGJAVA-1085\\";
String outputPath = basePath + "output\\";
File dir = new File(outputPath);
if (!dir.exists())
{
assert dir.mkdirs() : "Can not create output directory!";
}
for (String fileName : testFiles)
{
String inputFileName = basePath + fileName;
String outputFileName = outputPath + fileName + ".emf";
final Image image = Image.load(inputFileName);
try
{
image.save(outputFileName, new EmfOptions()
{{
setVectorRasterizationOptions(new SvgRasterizationOptions()
{{
setPageSize(Size.to_SizeF(image.getSize()));
}});
}});
}
finally
{
image.close();
}
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// create new synchronized two-way stream
com.aspose.imaging.StreamContainer streamContainer = new com.aspose.imaging.StreamContainer(new java.io.ByteArrayInputStream(new byte[0]));
try
{
// check if the access to the stream source is synchronized.
synchronized (streamContainer.getSyncRoot())
{
// do work
// now access to streamContainer is synchronized
}
}
finally
{
streamContainer.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "AdjustingBrightness_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
//yar Image image = Image.load(dataDir + "aspose-logo.dxf");
// Adjust the brightness
image.adjustBrightness(50);
// Create an instance of BmpOptions for the resultant image and Save the
// resultant image
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
}
catch (FileNotFoundException ex) {
Logger.getLogger(AdjustingBrightness.class.getName()).log(Level.SEVERE, null, ex);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "AdjustingContrast_out.bmp";
// Load a DICOM image in an instance of DicomImage
File file = new File(inputFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Adjust the contrast
image.adjustContrast(50);
// Create an instance of BmpOptions for the resultant image and Save the
// resultant image
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
}
catch (FileNotFoundException ex)
{
Logger.getLogger(AdjustingBrightness.class.getName()).log(Level.SEVERE, null, ex);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "AdjustingGamma.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Adjust the gamma
image.adjustGamma(50);
// Create an instance of BmpOptions for the resultant image and Save the
// resultant image
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
}
catch (FileNotFoundException ex)
{
Logger.getLogger(AdjustingBrightness.class.getName()).log(Level.SEVERE, null, ex);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "ApplyFilterOnDICOMImage_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Load an image
// Supply the filters to DICOM image.
image.filter(image.getBounds(), new com.aspose.imaging.imagefilters.filteroptions.MedianFilterOptions(8));
// Save the results to output path.
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
}
catch (FileNotFoundException ex)
{
Logger.getLogger(AdjustingBrightness.class.getName()).log(Level.SEVERE, null, ex);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "BinarizationwithBradleyAdaptiveThreshold_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Binarize image with bradley's adaptive threshold.
image.binarizeBradley(10);
// Save the resultant image.
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
}
catch (FileNotFoundException ex)
{
Logger.getLogger(AdjustingBrightness.class.getName()).log(Level.SEVERE, null, ex);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "BinarizationwithFixedThreshold_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
//try {
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Binarize image with predefined fixed threshold.
image.binarizeFixed((byte) 100);
// Save the resultant image.
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "BinarizationwithOtsuThreshold_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Binarize image with Otsu Thresholding.
image.binarizeOtsu();
// Save the resultant image.
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "CropbyShifts_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
//try {
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Call and supply the four values to Crop method.
image.crop(10, 20, 30, 40);
// Save the results to disk
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "DitheringForDICOMImage_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Peform Threshold dithering on the image
image.dither(com.aspose.imaging.DitheringMethod.ThresholdDithering, 1);
// Save the image
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String dataDir = Utils.getSharedDataDir(FlipDICOMImage.class) + "dicom/";
String inputFile = dataDir + "image.dcm";
String outputFile = "FlipDICOMImage_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
image.rotateFlip(com.aspose.imaging.RotateFlipType.Rotate180FlipNone);
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "Grayscaling_out.bmp";
// Load an existing image.
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
// Transform image to its grayscale representation
image.grayscale();
// Save the resultant image.
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "ResizeHeightProportionally_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
image.resizeHeightProportionally(100, ResizeType.AdaptiveResample);
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "ResizeWidthProportionally_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
image.resizeWidthProportionally(150, ResizeType.AdaptiveResample);
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "RotateDICOMImage_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
image.rotate(10);
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputFile = dataDir + "image.dcm";
String outputFile = dataDir + "SimpleResizing_out.bmp";
File file = new File(inputFile);
FileInputStream fis = null;
fis = new FileInputStream(file);
// Load a DICOM image in an instance of DicomImage
com.aspose.imaging.fileformats.dicom.DicomImage image = new com.aspose.imaging.fileformats.dicom.DicomImage(fis);
image.resize(200, 200);
image.save(outputFile, new com.aspose.imaging.imageoptions.BmpOptions());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
//Create an instance of PngOptions
PngOptions exportOptions = new PngOptions();
//Set ColorType to Grayscale
exportOptions.setColorType(PngColorType.Grayscale);
//Create an instance of Rectangle and specify the portion on DjVu page
Rectangle exportArea = new Rectangle(0, 0, 2000, 2000);
//Specify the DjVu page index
int exportPageIndex = 2;
//Initialize an instance of DjvuMultiPageOptions
//while passing index of DjVu page index and instance of Rectangle
//covering the area to be exported
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(exportPageIndex, exportArea));
//Save the image
image.save(dataDir + "ConvertDjvuPagePortionToImage_out.png", exportOptions);
System.out.println("File conveted");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
//Create an instance of GifOptions with its default constructor
GifOptions exportOptions = new GifOptions();
//Set the resolution of resultant image
exportOptions.setResolutionSettings(new ResolutionSetting(300, 300));
//Set PaletteCorrection to false
exportOptions.setDoPaletteCorrection(false);
//Create an instance of 8bit palette and set it as Palette property for instance of GifOptions
exportOptions.setPalette(ColorPaletteHelper.create8Bit());
//Create an instance of IntRange and initialize it with range of pages to be exported
IntRange range = new IntRange(0, 2); //Export first 2 pages
//Initialize an instance of DjvuMultiPageOptions while passing instance of IntRange
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range));
//Call Save method while passing instance of GifOptions
image.save(dataDir + "ConvertDjvuPagesToGif_out.gif", exportOptions);
System.out.println("File conveted");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
//Create an instance of BmpOptions
BmpOptions exportOptions = new BmpOptions();
//Set BitsPerPixel for resultant images
exportOptions.setBitsPerPixel(32);
//Create an instance of IntRange and initialize it with range of pages to be exported
IntRange range = new IntRange(0, 2); //Export first 2 pages
int counter = 0;
for (int i : range.getRange()) {
//Save each page in separate file, as BMP do not support layering
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range.getArrayOneItemFromIndex(counter)));
String output = dataDir + "ConvertDjvuPagesToImages_out" + (counter++) + ".bmp";
image.save(output, exportOptions);
}
// Display Status.
System.out.println("File conveted");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
//Create an instance of TiffOptions & use preset options for Black n While with Deflate compression
TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.TiffDeflateBw);
//Create an instance of IntRange and initialize it with range of pages to be exported
IntRange range = new IntRange(0, 2); //Export first 2 pages
//Initialize the DjvuMultiPageOptions
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range));
//Call Save method while passing instance of TiffOptions
image.save(dataDir + "ConvertDjvuPagesToTiff_out.tiff", exportOptions);
// Display Status.
System.out.println("File conveted");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
//Create an instance of PdfOptions
PdfOptions exportOptions = new PdfOptions();
//Initialize the metadata for Pdf document
exportOptions.setPdfDocumentInfo(new PdfDocumentInfo());
//Create an instance of IntRange and initialize it with the range of DjVu pages to be exported
IntRange range = new IntRange(0, 3); //Export first 3 pages
//Initialize an instance of DjvuMultiPageOptions with range of DjVu pages to be exported
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range));
//Save the result in PDF format
image.save(dataDir + "ConvertDjvuToPdf_out.pdf", exportOptions);
// Display Status.
System.out.println("File conveted");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
//Create an instance of TiffOptions & use preset options for Black n While with Deflate compression
TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.TiffDeflateBw);
//Initialize the DjvuMultiPageOptions
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions());
//Call Save method while passing instance of TiffOptions
image.save(dataDir + "ConvertDjvuToTiff_out.tiff", exportOptions);
// Display Status.
System.out.println("File conveted");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
// Create an instance of BmpOptions
BmpOptions exportOptions = new BmpOptions();
// Set BitsPerPixel for resultant images
exportOptions.setBitsPerPixel(32);
// Create an instance of IntRange and initialize it with range of pages
// to be exported
IntRange range = new IntRange(0, 2); //Export first 2 pages
int counter = 0;
for (int i : range.getRange()) {
// Save each page in separate file, as BMP do not support layering
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(range.getArrayOneItemFromIndex(counter)));
image.save(String.format("{0}.bmp", counter++), exportOptions);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Load a DjVu image
DjvuImage image = (DjvuImage) Image.load(dataDir + "Sample.djvu");
// Create an instance of PngOptions
PngOptions exportOptions = new PngOptions();
// Set ColorType to Grayscale
exportOptions.setColorType(PngColorType.Grayscale);
// Create an instance of Rectangle and specify the portion on DjVu page
Rectangle exportArea = new Rectangle(0, 0, 500, 500);
// Specify the DjVu page index
int exportPageIndex = 2;
// Initialize an instance of DjvuMultiPageOptions
// while passing index of DjVu page index and instance of Rectangle
// covering the area to be exported
exportOptions.setMultiPageOptions(new DjvuMultiPageOptions(exportPageIndex, exportArea));
// Save the image
image.save(dataDir + "ConvertSpecificPortionOfDjVuPage_out.djvu", exportOptions);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String dataDir = Utils.getSharedDataDir(SupportForEPS.class) + "EPS/";
EpsImage epsImage = (EpsImage)Image.load(dataDir+"anyEpsFile.eps");
try
{
// check if EPS image has any raster preview to proceed (for now only raster preview is supported)
if (epsImage.hasRasterPreview())
{
if (epsImage.getPhotoshopThumbnail() != null)
{
// process Photoshop thumbnail if it's present
}
if (epsImage.getEpsType() == EpsType.Interchange)
{
// Get EPS Interchange subformat instance
EpsInterchangeImage epsInterchangeImage = (EpsInterchangeImage)epsImage;
if (epsInterchangeImage.getRasterPreview() != null)
{
// process black-and-white Interchange raster preview if it's present
}
}
else
{
// Get EPS Binary subformat instance
EpsBinaryImage epsBinaryImage = (EpsBinaryImage)epsImage;
if (epsBinaryImage.getTiffPreview() != null)
{
// process TIFF preview if it's present
}
if (epsBinaryImage.getWmfPreview() != null)
{
// process WMF preview if it's present
}
}
// export EPS image to PNG (by default, best available quality preview is used for export)
epsImage.save(dataDir+"anyEpsFile.png", new PngOptions());
}
}
finally
{
epsImage.close();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load an existing image (of type Gif) in an instance of Image class
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dataDir + "sample.gif");
//Export to BMP file format using the default options
image.save(dataDir + "ExportImageToDifferentFormats_out.bmp" , new com.aspose.imaging.imageoptions.BmpOptions());
//Export to JPEG file format using the default options
image.save(dataDir + "ExportImageToDifferentFormats_out.jpeg", new com.aspose.imaging.imageoptions.JpegOptions());
//Export to PNG file format using the default options
image.save(dataDir + "ExportImageToDifferentFormats_out.png", new com.aspose.imaging.imageoptions.PngOptions());
//Export to TIFF file format using the default options
image.save(dataDir + "ExportImageToDifferentFormats_out.tiff", new TiffOptions(TiffExpectedFormat.Default));
// Display Status.
System.out.println("Image exported to BMP, JPG, PNG and TIFF formats successfully!");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Load an existing image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dataDir + "sample.bmp");
//Create an instance of PsdSaveOptions class
//Create an instance of PsdSaveOptions class
com.aspose.imaging.imageoptions.PsdOptions saveOptions = new com.aspose.imaging.imageoptions.PsdOptions();
//Set the CompressionMethod as Raw
//Note: Other supported CompressionMethod is CompressionMethod.Rle [No Compression]
saveOptions.setCompressionMethod(CompressionMethod.Raw);
//Set the ColorMode to GrayScale//Note: Other supported ColorModes are ColorModes.Bitmap and ColorModes.RGB
saveOptions.setColorMode(ColorModes.Rgb);
//Save the image to disk location with supplied PsdOptions settings
image.save(dataDir + "ExportImageToPSD_out.psd", saveOptions);
// Display Status.
System.out.println("Image exported to PSD successfully!");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String inputPath = dataDir + "conic_pyramid.dxf";
Image image = Image.load(dataDir + "sample.psd");
PsdImage psdImage = (PsdImage) image;
PngOptions pngOptions = new PngOptions();
pngOptions.setColorType(PngColorType.TruecolorWithAlpha);
for (int i = 0; i < psdImage.getLayers().length; i++) {
psdImage.getLayers()[i].save(dataDir + "ExportPsdLayersToImages_out" + i + ".png", pngOptions);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String sourcepath = dataDir + "aspose_logo.png";
String outputPath = dataDir + "UseBradleythresholding_out.png";
// Load an existing image.
com.aspose.imaging.fileformats.png.PngImage objimage = (com.aspose.imaging.fileformats.png.PngImage) com.aspose.imaging.Image
.load(sourcepath);
// Define threshold value
double threshold = 0.15;
// Call BinarizeBradley method and pass the threshold value as parameter
objimage.binarizeBradley(threshold);
// Save the output image
objimage.save(outputPath);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Creates an instance of BmpOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions createOptions = new com.aspose.imaging.imageoptions.BmpOptions();
createOptions.setBitsPerPixel(24);
//Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
//If second parameter is not passed, then by default the file has IsTemporal set to True
createOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dataDir + "sample.bmp"));
//Creates an instance of Image
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(createOptions,500,500);
image.save();
// Display Status.
System.out.println("Image created successfully!");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
com.aspose.imaging.Metered metered = new com.aspose.imaging.Metered();
// Access the setMeteredKey property and pass public and private keys as parameters
metered.setMeteredKey("<valid pablic key>", "<valid private key>");
// Get consumed qantity value before accessing API
System.out.println("Consumption quantity" + com.aspose.imaging.Metered.getConsumptionQuantity());
// DO PROCESSING
//com.aspose.imaging.Image img = com.aspose.imaging.Image.load("C:\\in.psd");
//img.save("C:\\Temp\\out.psd");
//Since upload data is running on another thread, so we need wait some time
//java.lang.Thread.sleep(10000);
// get metered data amount
System.out.println("Consumption quantity" + com.aspose.imaging.Metered.getConsumptionQuantity());
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Create an Image object and load an existing file using the file path
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dataDir + "sample.bmp");
//Print message
System.out.println("Image is loaded successfully.");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Create an Image Object and open an existing file using the Stream
// Object
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(stream);
// do some image processing
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ReadingPixelVaules.class) + "files/";
//String dir = "C:\\Errors\\1006\\";
String fileName = "16bit Uncompressed, BigEndian, Rgb, Contiguous Gamma1.0.tif";
// ICC profile is not applied for 16-bit color components at the moment, so disable that option explicitly.
LoadOptions loadOptions = new LoadOptions();
loadOptions.setUseIccProfileConversion(false);
Rectangle desiredArea = new Rectangle(470, 1350, 30, 30);
RasterImage image = (RasterImage)Image.load(dataDir + fileName, loadOptions);
try
{
long[] colors64Bit = image.loadArgb64Pixels(image.getBounds());
int alpha, red, green, blue;
for (int y = desiredArea.getTop(); y < desiredArea.getBottom(); ++y)
{
for (int x = desiredArea.getLeft(); x < desiredArea.getRight(); ++x)
{
int offset = y * image.getWidth() + x;
long color64 = colors64Bit[offset];
alpha = (int)((color64 >> 48) & 0xffff);
red = (int)((color64 >> 32) & 0xffff);
green = (int)((color64 >> 16) & 0xffff);
blue = (int)(color64 & 0xffff);
System.out.format("A=%X, R=%X, G=%X, B=%X\n", alpha, red, green, blue);
}
}
}
finally{
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir + "aspose-logo.jpg");
image.save("SavingtoDisk_out.bmp");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
java.io.OutputStream os = new java.io.FileOutputStream("C:\\SavingtoStream_out.bmp");
Image image = Image.load(dataDir + "aspose-logo.jpg");
//Save the image using the Save method exposed by the Image class and pass the outputstream object
image.save(os);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Create an instance of Image and load an existing image.
Image image= Image.load(dataDir + "sample.bmp");
//Create and initialize an instance of Graphics class.
Graphics graphics=new Graphics(image);
//Creates an instance of Font
Font font = new Font("Times New Roman", 16, FontStyle.Bold);
//Create an instance of SolidBrush and set its various properties.
SolidBrush brush = new SolidBrush();
brush.setColor(Color.getBlack());
brush.setOpacity(100);
//Draw a String using the SolidBrush object and Font, at specific Point.
graphics.drawString("Aspose.Imaging for .Net", font, brush, new PointF(image.getWidth()-100, image.getHeight()-100));
// save the image with changes
image.save(dataDir + "AddWatermarkToImage_out.bmp");
// Display Status.
System.out.println("Watermark added successfully!");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
com.aspose.imaging.imageoptions.JpegOptions ImageOptions = new com.aspose.imaging.imageoptions.JpegOptions();
// Create an instance of FileCreateSource and assign it to Source
// property
ImageOptions.setSource(
new com.aspose.imaging.sources.FileCreateSource(dataDir + "two_images_result.jpeg", false));
// Create an instance of Image
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(ImageOptions, 600, 600);
// Create and initialize an instance of Graphics
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
// Clear the image surface with white color
graphics.clear(com.aspose.imaging.Color.getWhite());
// Draw Image
graphics.drawImage(com.aspose.imaging.Image.load(dataDir + "aspose-logo.jpg"), 0, 0, 600, 300);
// Call save method to save the resultant image.
image.save();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Create an instance of TiffImage and load the copied destination image
TiffImage image1 = (TiffImage) com.aspose.imaging.Image.load(dataDir + "TestDemo.tif");
// Create an instance of TiffImage and load the source image
TiffImage image2 = (TiffImage) com.aspose.imaging.Image.load(dataDir + "sample.tif");
// Create an instance of TIffFrame and copy active frame of source image
TiffFrame frame = TiffFrame.copyFrame(image2.getActiveFrame());
// Add copied frame to destination image
image1.addFrame(frame);
// save the image with changes.
image1.save();
// Display Status.
System.out.println("Concatenation of TIF files done successfully!");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Create an instance of BmpCreateOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions createOptions = new com.aspose.imaging.imageoptions.BmpOptions();
createOptions.setBitsPerPixel(24);
//Create an instance of FileCreateSource and assign it to Source property
createOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dataDir + "sample.bmp",false));
//Create an instance of RasterImage
RasterImage rasterImage = (RasterImage) RasterImage.create(createOptions, 500, 500);
//Get the pixels of the image by specifying the area as image boundary
com.aspose.imaging.Color [] pixels = rasterImage.loadPixels(rasterImage.getBounds());
for (int index = 0; index < pixels.length; index++)
{
//Set the indexed pixel color to yellow
pixels[index] = com.aspose.imaging.Color.getYellow();
}
rasterImage.savePixels(rasterImage.getBounds(), pixels);
// Save processed image.
rasterImage.save();
// Display Status.
System.out.println("Processing completed successfully!");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Creates an instance of BmpOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions bmpCreateOptions = new com.aspose.imaging.imageoptions.BmpOptions();
bmpCreateOptions.setBitsPerPixel(32);
// Define the source property for the instance of BmpCreateOptions
bmpCreateOptions.setSource(
new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[100 * 100 * 4])));
// Creates an instance of Image and call Create method by passing the
// BmpOptions object
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpCreateOptions, 100, 100);
// Create and initialize an instance of Graphics class
com.aspose.imaging.Graphics graphic = new com.aspose.imaging.Graphics(image);
// Clear the image surface with Yellow color
graphic.clear(com.aspose.imaging.Color.getYellow());
// Draw a dotted arc shape by specifying the Pen object having red black
// color and coordinates, height, width, start & end angles
int width = 100;
int height = 200;
int startAngle = 45;
int sweepAngle = 270;
// Draw arc to screen.
graphic.drawArc(new Pen(com.aspose.imaging.Color.getBlack()), 0, 0, width, height, startAngle, sweepAngle);
// Save all changes.
image.save(dataDir + "DrawingArc_out.bmp");
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
com.aspose.imaging.imageoptions.BmpOptions bmpCreateOptions = new com.aspose.imaging.imageoptions.BmpOptions();
bmpCreateOptions.setBitsPerPixel(32);
// Define the source property for the instance of BmpOptions
bmpCreateOptions.setSource(
new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[100 * 100 * 4])));
// Creates an instance of Image and call create method by passing the
// bmpCreateOptions object
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpCreateOptions, 100, 100);
// Create and initialize an instance of Graphics class
com.aspose.imaging.Graphics graphic = new com.aspose.imaging.Graphics(image);
// Clear the image surface with Yellow color
graphic.clear(com.aspose.imaging.Color.getYellow());
// Draw a dotted ellipse shape by specifying the Pen object having red
// color and a surrounding Rectangle
graphic.drawEllipse(new Pen(com.aspose.imaging.Color.getRed()),
new com.aspose.imaging.Rectangle(30, 10, 40, 80));
// Draw a continuous ellipse shape by specifying the Pen object having
// solid brush with blue color and a surrounding Rectangle
graphic.drawEllipse(new Pen(new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getBlue())),
new com.aspose.imaging.Rectangle(10, 30, 80, 40));
// Save all changes.
image.save(dataDir + "DrawingEllipse_out.bmp");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
com.aspose.imaging.imageoptions.BmpOptions bmpCreateOptions = new com.aspose.imaging.imageoptions.BmpOptions();
bmpCreateOptions.setBitsPerPixel(32);
// Define the source property for the instance of BmpOptions
bmpCreateOptions.setSource(
new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[100 * 100 * 4])));
// Creates an instance of Image and call create method by passing the
// bmpCreateOptions object
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpCreateOptions, 100, 100);
// Create and initialize an instance of Graphics class
com.aspose.imaging.Graphics graphic = new com.aspose.imaging.Graphics(image);
// Clear the image surface with Yellow color
graphic.clear(com.aspose.imaging.Color.getYellow());
// Draw a dotted line by specifying the Pen object having blue color and
// co-ordinate Points
graphic.drawLine(new Pen(com.aspose.imaging.Color.getBlue()), 9, 9, 90, 90);
graphic.drawLine(new Pen(com.aspose.imaging.Color.getBlue()), 9, 90, 90, 9);
// Draw a continuous line by specifying the Pen object having Solid
// Brush with red color and two point structures
graphic.drawLine(new Pen(new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getRed())),
new com.aspose.imaging.Point(9, 9), new com.aspose.imaging.Point(9, 90));
// Draw a continuous line by specifying the Pen object having Solid
// Brush with aqua color and two point structures
graphic.drawLine(new Pen(new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getAqua())),
new com.aspose.imaging.Point(9, 90), new com.aspose.imaging.Point(90, 90));
// Draw a continuous line by specifying the Pen object having Solid
// Brush with black color and two point structures
graphic.drawLine(new Pen(new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getBlack())),
new com.aspose.imaging.Point(90, 90), new com.aspose.imaging.Point(90, 9));
// Draw a continuous line by specifying the Pen object having Solid
// Brush with white color and two point structures
graphic.drawLine(new Pen(new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getWhite())),
new com.aspose.imaging.Point(90, 9), new com.aspose.imaging.Point(9, 9));
// Save all changes.
image.save(dataDir + "DrawingLines_out.bmp");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Creates an instance of BmpOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions bmpCreateOptions = new com.aspose.imaging.imageoptions.BmpOptions();
bmpCreateOptions.setBitsPerPixel(32);
// Define the source property for the instance of BmpOptions
bmpCreateOptions.setSource(
new com.aspose.imaging.sources.StreamSource(new java.io.ByteArrayInputStream(new byte[100 * 100 * 4])));
// Creates an instance of Image and call Create method by passing the
// bmpCreateOptionsobject
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpCreateOptions, 100, 100);
// Create and initialize an instance of Graphics class
com.aspose.imaging.Graphics graphic = new com.aspose.imaging.Graphics(image);
// Clear the image surface with Yellow color
graphic.clear(com.aspose.imaging.Color.getYellow());
// Draw a dotted rectangle shape by specifying the Pen object having red
// color and a rectangle structure
graphic.drawRectangle(new Pen(com.aspose.imaging.Color.getRed()),
new com.aspose.imaging.Rectangle(30, 10, 40, 80));
// Draw a continuous rectangle shape by specifying the Pen object having
// solid brush with blue color and a rectangle structure
graphic.drawRectangle(new Pen(new com.aspose.imaging.brushes.SolidBrush(com.aspose.imaging.Color.getBlue())),
new com.aspose.imaging.Rectangle(10, 30, 80, 40));
// Save all changes.
image.save(dataDir + "DrawingRectangle_out.bmp");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Create an instance of BmpCreateOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions createOptions = new com.aspose.imaging.imageoptions.BmpOptions();
createOptions.setBitsPerPixel(24);
//Create an instance of FileCreateSource and assign it to Source property
createOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dataDir + "sample.bmp",false));
//Create an instance of Image
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(createOptions,500,500);
//Create and initialize an instance of Graphics
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
//Clear the image surface with white color
graphics.clear(Color.getWhite());
//Create and initialize a Pen object with blue color
com.aspose.imaging.Pen pen = new com.aspose.imaging.Pen(com.aspose.imaging.Color.getBlue());
//Draw Ellipse by defining the bounding rectangle of width 150 and height 100
graphics.drawEllipse(pen, new com.aspose.imaging.Rectangle(10, 10, 150, 100));
// Save all changes.
image.save(dataDir + "DrawingusingGraphics_out.bmp");
//Print message
System.out.println("Image drawn successfully. Check output file.");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//Create an instance of BmpCreateOptions and set its various properties
com.aspose.imaging.imageoptions.BmpOptions createOptions = new com.aspose.imaging.imageoptions.BmpOptions();
createOptions.setBitsPerPixel(24);
//Create an instance of FileCreateSource and assign it to Source property
createOptions.setSource(new com.aspose.imaging.sources.FileCreateSource(dataDir + "sample.bmp",false));
//Create an instance of Image
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(createOptions,500,500);
//Create and initialize an instance of Graphics
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
//Clear the image surface with white color
graphics.clear(Color.getWhite());
//Create an instance of GraphicsPath
com.aspose.imaging.GraphicsPath graphicspath = new com.aspose.imaging.GraphicsPath();
//Create an instance of Figure
com.aspose.imaging.Figure figure = new com.aspose.imaging.Figure();
//Add Arc shape to the figure by defining boundary Rectangle
figure.addShape(new com.aspose.imaging.shapes.ArcShape(new RectangleF(10, 10, 300, 300), 0, 45));
//Add Arc Polygon shape to the figure by defining boundary Rectangle
figure.addShape(new com.aspose.imaging.shapes.PolygonShape(new PointF[]{new PointF(150, 10), new PointF(150, 200), new PointF(250, 300), new PointF(350, 400)}, true));
//Add Arc Polygon shape to the figure by defining boundary Rectangle
figure.addShape(new com.aspose.imaging.shapes.RectangleShape(new RectangleF(new PointF(250, 250), new SizeF(200, 200))));
//Add figures to the GraphicsPath object
graphicspath.addFigures(new Figure[]{ figure});
//Draw Path
graphics.drawPath(new Pen(com.aspose.imaging.Color.getBlack(), 2), graphicspath);
//Create an instance of HatchBrush and set its properties
com.aspose.imaging.brushes.HatchBrush hatchbrush = new com.aspose.imaging.brushes.HatchBrush();
hatchbrush.setBackgroundColor( com.aspose.imaging.Color.getBrown()); hatchbrush.setForegroundColor ( com.aspose.imaging.Color.getBlue());
hatchbrush.setHatchStyle (HatchStyle.Vertical);
//Fill path by supplying the brush and GraphicsPath objects
graphics.fillPath(hatchbrush, graphicspath);
// Save the final image.
image.save();
// Display Status.
System.out.println("Processing completed successfully!");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
PsdImage image = (PsdImage)Image.load(dataDir+"input.psd");
try
{
image.save("NoFont.psd");
}
finally
{
image.dispose();
}
System.out.println("You have 2 minutes to install the font");
Thread.sleep(2 * 60 * 1000);
OpenTypeFontsCache.updateCache();
image = (PsdImage)Image.load("input.psd");
try
{
image.save("HasFont.psd");
}
finally
{
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String path = dataDir + "aspose-logo.jpg";
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) Image.load(path);
try {
// gets the date from [FileInfo]
String modifyDate = image.getModifyDate(true).toString();
System.out.format("Last modify date using FileInfo: %s\n", modifyDate);
// gets the date from XMP metadata of [FileInfo] as long as it's not
// default case
modifyDate = image.getModifyDate(false).toString();
System.out.format("Last modify date using info from FileInfo and XMP metadata: %s\n", modifyDate);
} finally {
image.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
// Sets the maximum allowed pixel difference. If greater than zero, lossy compression will be used.
// Recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy.
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dataDir + "aspose-logo.gif");
GifOptions gifExport = new GifOptions();
gifExport.setMaxDiff(80);
image.save(dataDir+"anim_lossy-80.gif", gifExport);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
String fileName = "testReplacementNotAvailableFonts.psd";
PsdImage image = (PsdImage)Image.load(fileName, new PsdLoadOptions(){{ setDefaultReplacementFont ("Arial"); }});
try
{
image.save("result.png", new PngOptions() {{ setColorType(PngColorType.TruecolorWithAlpha); }});
}
finally
{
image.dispose();
}
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SupportOfDIB.class) + "images/";
Image image = Image.load(dataDir + "sample.dib");
try {
System.out.println(FileFormat.toString(FileFormat.class, image.getFileFormat())); // Output is "Bmp"
image.save(dataDir + "sample.png", new PngOptions());
} finally {
image.close();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
//String dir = "C:\\Temp\\Errors\\";
String dataDir = Utils.getSharedDataDir(SupportForInterruptMonitor.class) + "InterruptMonitor/";
ImageOptionsBase saveOptions = new PngOptions();
InterruptMonitor monitor = new InterruptMonitor();
SaveImageWorker worker = new SaveImageWorker(dataDir + "big.jpg", dataDir + "big_out.png", saveOptions, monitor);
Thread thread = new Thread(worker);
try
{
thread.start();
// The timeout should be less than the time required for full image conversion (without interruption).
Thread.sleep(3000);
// Interrupt the process
System.out.format("Interrupting the save thread #%d at %s\n", thread.getId(), new Date().toString());
monitor.interrupt();
// Wait for interruption...
thread.join();
}
finally
{
// If the file to be deleted does not exist, no exception is thrown.
File f = new File(dataDir + "big_out.png");
f.delete();
}
}
/**
* Initiates image conversion and waits for its interruption.
*/
private class SaveImageWorker implements Runnable
{
/**
* The path to the input image.
*/
private final String inputPath;
/**
* The path to the output image.
*/
private final String outputPath;
/**
* The interrupt monitor.
*/
private final InterruptMonitor monitor;
/**
* The save options.
*/
private final ImageOptionsBase saveOptions;
/**
* Initializes a new instance of the SaveImageWorker class.
* @param inputPath The path to the input image.
* @param outputPath The path to the output image.
* @param saveOptions The save options.
* @param monitor The interrupt monitor.
*/
public SaveImageWorker(String inputPath, String outputPath, ImageOptionsBase saveOptions, InterruptMonitor monitor)
{
this.inputPath = inputPath;
this.outputPath = outputPath;
this.saveOptions = saveOptions;
this.monitor = monitor;
}
/**
* Tries to convert image from one format to another. Handles interruption.
*/
public void run()
{
Image image = Image.load(this.inputPath);
try
{