Using Aspose.Total for Java , you can convert JSON format to DICOM within any Java application in two simple steps. Firstly, by using Aspose.Cells for Java , you can parse JSON to JPEG. After that, by using Aspose.Imaging for Java , you can convert JPEG to DICOM.
Convert JSON Format to DICOM via Java
Conversion Requirements
You can easily use Aspose.Total for Java directly from a Maven based project and include libraries in your pom.xml.
Alternatively, you can get a ZIP file from downloads .
// open JSON file using Workbook object | |
Workbook workbook = new Workbook("input.json"); | |
// save resultant file in JSON-TO-JPEG ormat | |
workbook.save("output.jpeg", SaveFormat.AUTO); | |
// load JPEG file | |
Image image = Image.Load("output.jpeg"); | |
// supports DICOM, JPEG2000, APNG, PSD, DXF, WMF, EMZ, WMZ, TGA, and SVGZ file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Set Layout and Convert JSON Format to DICOM via Java
Furthermore, the API allows you to parse JSON to DICOM with specified layout options. In order to specify the layout options, you can use JsonLayoutOptions class. It allows you to process an array as a table, ignore nulls, ignore array title, ignore object title, convert string to number or date, set date and number format, and set title style. All of these options allow you to present your data as per your needs. The following code snippet shows you how to set the layout options.
// create a blank Workbook object | |
Workbook workbook = new Workbook("input.json"); | |
// access default empty worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// read JSON file | |
String jsonInput = new String(Files.readAllBytes("SampleJson.json")); | |
// set JsonLayoutOptions for formatting | |
JsonLayoutOptions layoutOptions = new JsonLayoutOptions(); | |
layoutOptions.setArrayAsTable(true); | |
layoutOptionssetConvertNumericOrDate(true); | |
layoutOptionssetIgnoreArrayTitle(true); | |
layoutOptionssetIgnoreNull(true); | |
layoutOptionssetIgnoreObjectTitle(true); | |
// import JSON data to default worksheet starting at cell A1 | |
JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, layoutOptions); | |
// save resultant file in JSON-TO-JPEG ormat | |
workbook.save("output.jpeg", SaveFormat.AUTO); | |
// load JPEG file | |
Image image = Image.Load("output.jpeg"); | |
// supports DICOM, JPEG2000, APNG, PSD, DXF, WMF, EMZ, WMZ, TGA, and SVGZ file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Convert JSON Format to DICOM with Watermark via Java
Using the API, you can also convert JSON to DICOM with watermark in your DICOM document. In order to add a watermark to you can first convert JSON to JPEG and add a watermark in it. In order to add watermark, load an image file using the Image class, create an object of the Graphics class and initialize it with Image object, create a new Matrix object and set translation and transformation to the desired angle and add watermark using Graphics.drawString method. After adding the watermark in your image, you can save the JPEG as DICOM format.
// open JSON file using Workbook object | |
Workbook workbook = new Workbook("input.json"); | |
// save resultant file in JSON-TO-JPEG ormat | |
workbook.save("output.jpeg", SaveFormat.AUTO); | |
// load JPEG | |
Image image = Image.load("output.jpeg"); | |
// create and initialize an instance of Graphics class | |
Graphics graphics= new Graphics(image); | |
// create an instance of Font | |
Font font = new Font("Times New Roman", 16, FontStyle.Bold); | |
// create an instance of SolidBrush and set its properties | |
SolidBrush brush = new SolidBrush(); | |
brush.setColor(Color.getBlack()); | |
brush.setOpacity(100); | |
Size sz = graphics.getImage().getSize(); | |
// create an object of Matrix class for transformation | |
Matrix matrix = new Matrix(); | |
// first a translation then a rotation | |
matrix.translate(sz.getWidth() / 2, sz.getHeight() / 2); | |
matrix.rotate(-45.0f); | |
// set the Transformation through Matrix | |
graphics.setTransform(matrix); | |
// draw a string using the SolidBrush and Font objects at specific point | |
graphics.drawString("Watermark by Aspose.Imaging for Java", font, brush, 0, 0); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Explore JSON Conversion Options with Java
What is JSON File Format?
The JSON (JavaScript Object Notation) file format is a lightweight and widely used data interchange format. It was derived from the JavaScript programming language but is now language-independent and supported by various programming languages. JSON files store data in a structured and readable format, making them easy to understand and process by both humans and machines.
JSON files consist of key-value pairs organized in a hierarchical structure. They represent data in a simple and intuitive way using objects (enclosed in curly braces {}) and arrays (enclosed in square brackets []). Each key is paired with a corresponding value, which can be a string, number, boolean, null, object, or array. This flexibility allows JSON to handle complex and nested data structures.
One of the main advantages of JSON is its simplicity and ease of use. Its lightweight nature and minimal syntax make it efficient for data transmission over networks and storage in files. JSON files are commonly used for data exchange between web servers and clients, as well as for configuration files, APIs, and storing structured data.
JSON files are human-readable and can be easily understood and modified using a text editor. They are also machine-readable, allowing applications to parse and process JSON data efficiently. Many programming languages provide built-in libraries or packages for working with JSON, simplifying the parsing and serialization of JSON data.
What is DICOM File Format?
Digital Imaging and Communications in Medicine (DICOM) is a standard for storing and transmitting medical images. It includes a file format definition and a network protocol. DICOM files can be exchanged between two entities, such as a medical imaging device and a picture archiving and communication system (PACS), or between two PACS. DICOM enables the integration of medical imaging devices and information systems.DICOM files are composed of a file header and a series of data sets. The file header contains information about the file, such as the DICOM version, the transfer syntax used, the patients name, and the study date. The data sets contain the image data and associated information, such as the patient ID, the image modality, and the image orientation.DICOM files can be exchanged over a network using the DICOM protocol. The DICOM protocol is a set of rules that define how DICOM files are to be transmitted. The protocol is based on the TCP/IP protocol.