Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/05eb9605b16ab5de85e0ecb2d7e80b3f to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/05eb9605b16ab5de85e0ecb2d7e80b3f to your computer and use it in GitHub Desktop.
Convert JSON to Image in Java

Convert JSON to Image via Aspose.Total for Java

Powerful Java File Format Automation APIs to parse JSON format to DICOM, JPEG2000, APNG, PSD, DXF, WMF, EMZ, WMZ, TGA, and SVGZ file formats

The below Java code example demonstrates how to parse JSON to PSD. More details at https://products.aspose.com/total/java/conversion/json-to-psd/

Furthmore, you can alse set Layout Options for JSON file foramt and add Watermark in your output PSD file format .

Installation

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
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());
// 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());
// 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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment