Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active August 2, 2023 14:59

Aspose.Imaging Java API allows allows programmatically convert your Dicom images to various image formats with high quality in your Java application or Web service.

You can:

  • convert Dicom pages to images;
  • convert Dicom image to multi page (i.e. pdf) or multi frame image formats;

Interested ?

You may go further at : https://products.aspose.com/imaging/java/

import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of ApngOptions
ApngOptions exportOptions = new ApngOptions();
// Save dicom to apng
image.save(outputFolder + File.separator + "dicom-to-apng-output.apng", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of BmpOptions
BmpOptions exportOptions = new BmpOptions();
// Save dicom to bmp
image.save(outputFolder + File.separator + "dicom-to-bmp-output.bmp", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of DicomOptions
DicomOptions exportOptions = new DicomOptions();
// Save dicom to dicom
image.save(outputFolder + File.separator + "dicom-to-dicom-output.dicom", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
DxfOptions exportOptions = new DxfOptions();
// Save dicom to dxf
image.save(outputFolder + File.separator + "dicom-to-dxf-output.dxf", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of EmfOptions
EmfOptions exportOptions = new EmfOptions();
// Save dicom to emf
image.save(outputFolder + File.separator + "dicom-to-emf-output.emf", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
EmfOptions exportOptions = new EmfOptions();
exportOptions.setCompress(true);
// Save dicom to emz
image.save(outputFolder + File.separator + "dicom-to-emz-output.emz", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of GifOptions
GifOptions exportOptions = new GifOptions();
// Save dicom to gif
image.save(outputFolder + File.separator + "dicom-to-gif-output.gif", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
Html5CanvasOptions exportOptions = new Html5CanvasOptions();
// Save dicom to html
image.save(outputFolder + File.separator + "dicom-to-html-output.html", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of IcoOptions
IcoOptions exportOptions = new IcoOptions();
// Save dicom to ico
image.save(outputFolder + File.separator + "dicom-to-ico-output.ico", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
import com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Codec;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
Jpeg2000Options exportOptions = new Jpeg2000Options();
exportOptions.setCodec(Jpeg2000Codec.J2K);
// Save dicom to j2k
image.save(outputFolder + File.separator + "dicom-to-j2k-output.j2k", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
import com.aspose.imaging.fileformats.jpeg2000.Jpeg2000Codec;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
Jpeg2000Options exportOptions = new Jpeg2000Options();
exportOptions.setCodec(Jpeg2000Codec.Jp2);
// Save dicom to jp2
image.save(outputFolder + File.separator + "dicom-to-jp2-output.jp2", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of JpegOptions
JpegOptions exportOptions = new JpegOptions();
// Save dicom to jpeg
image.save(outputFolder + File.separator + "dicom-to-jpeg-output.jpeg", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of Jpeg2000Options
Jpeg2000Options exportOptions = new Jpeg2000Options();
// Save dicom to jpeg2000
image.save(outputFolder + File.separator + "dicom-to-jpeg2000-output.jpeg2000", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
JpegOptions exportOptions = JpegOptions();
// Save dicom to jpg
image.save(outputFolder + File.separator + "dicom-to-jpg-output.jpeg", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of PdfOptions
PdfOptions exportOptions = new PdfOptions();
// Save dicom to pdf
image.save(outputFolder + File.separator + "dicom-to-pdf-output.pdf", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of PngOptions
PngOptions exportOptions = new PngOptions();
// Save dicom to png
image.save(outputFolder + File.separator + "dicom-to-png-output.png", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of PsdOptions
PsdOptions exportOptions = new PsdOptions();
// Save dicom to psd
image.save(outputFolder + File.separator + "dicom-to-psd-output.psd", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of SvgOptions
SvgOptions exportOptions = new SvgOptions();
// Save dicom to svg
image.save(outputFolder + File.separator + "dicom-to-svg-output.svg", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
SvgOptions exportOptions = new SvgOptions();
exportOptions.setCompress(true);
// Save dicom to svgz
image.save(outputFolder + File.separator + "dicom-to-svgz-output.svgz", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of TgaOptions
TgaOptions exportOptions = new TgaOptions();
// Save dicom to tga
image.save(outputFolder + File.separator + "dicom-to-tga-output.tga", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
import com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.Default);
// Save dicom to tif
image.save(outputFolder + File.separator + "dicom-to-tif-output.tiff", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
import com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
TiffOptions exportOptions = new TiffOptions(TiffExpectedFormat.Default);
// Save dicom to tiff
image.save(outputFolder + File.separator + "dicom-to-tiff-output.tiff", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
WebPOptions exportOptions = new WebPOptions();
// Save dicom to webp
image.save(outputFolder + File.separator + "dicom-to-webp-output.webp", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
// Create an instance of WmfOptions
WmfOptions exportOptions = new WmfOptions();
// Save dicom to wmf
image.save(outputFolder + File.separator + "dicom-to-wmf-output.wmf", exportOptions);
}
}
}
import java.io.File;
import com.aspose.imaging.Image;
import com.aspose.imaging.imageoptions.*;
//You can get all image templates from https://github.com/aspose-imaging/Aspose.Imaging-for-Java/blob/master/Examples/Data/Templates.zip
//After download archive please unpack it and replace templatesFolder variable path with your path to unpacked archive folder
public class Main {
public static void main(String[] args) {
// get path of the input data
String templatesFolder = System.getenv("DATA_PATH");
// get output path
String outputFolder = System.getenv("OUT_PATH");
if (templatesFolder == null)
templatesFolder = "data";
if (outputFolder == null)
outputFolder = "out";
// Load the dicom file in an instance of Image
try (Image image = Image.load(templatesFolder + File.separator + "template.dicom")) {
WmfOptions exportOptions = new WmfOptions();
exportOptions.setCompress(true);
// Save dicom to wmz
image.save(outputFolder + File.separator + "dicom-to-wmz-output.wmz", exportOptions);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment