Georgia Ingham Georgia is a Java Developer. She has spoken at lots of conferences. Her hobbies include reading, completing puzzle books and cycling.

Are you a Java Developer working with Image files?

Read and write images in Java with JDeli

How to view Photoshop images in Java?

1 min read

This week sees an interesting addition to our JDeli image library. We have now developed our own PSD decoder. In this blog article I will be explaining: what the PSD file format is, what it is used for and how you can use it as part of our JDeli library.

Where have I heard of PSD?

If you have ever used Adobe’s Photoshop software then you will no doubt have seen this type of file before. PSD stands for PhotoShop Document and is Adobe’s layered image file format. Photoshop’s popularity has shown that the PSD format has pretty much become a standard in the bitmapped image world.

PSD files can have a maximum height and width of 30,000 pixels. PSD file sizes can reach up to 2GB.  Adobe has also enforced a limit of no more than 8000 layers (though not many people ever get past the 6000 layer mark).

Why would I want to use this format?

This format was primarily made to preserve multiple layers of graphics art in a saved file. By doing this it meant that further editing could be carried out later. The preservation of each layer and their states allows the user the ability to edit each individual layer or graphics object separately. Ultimately giving you a lot more control over how to construct and edit your images over time. PSD files can also store information regarding applied masks, transparency values, text, colours used and clipping paths among other alterations for each individual layer.

The beauty of having multiple image layers enables illustrations to be created where objects can be moved, stretched, cropped and generally edited without other layers being affected. On top of that layers can easily be reordered or made invisible to suit your needs. PSD also allows for the combination of both pixel and vector based objects, lifting the restriction on using either one or the other.

Once you are happy with your PSD you can effectively flatten it to create a final image which can be exported to many different image formats including JPEG and GIF’s. The PSD file is kept as a sort of blueprint which you can go back to, easily edit and again create a file in a format that is suitable for your required purpose.

How do I decode this format in JDeli?

As I mentioned previously, PSD documents are editable blueprints that can be used to create a final image in a different file format e.g. PNG. JDeli allows us to easily get the final image data so that it can be used with another encoder or image writer later. e.g.

 RandomAccessFile raf = new RandomAccessFile("C:\path\to\your\file.psd", "r");
 PsdDecoder decoder = new PsdDecoder(raf);
 BufferedImage decodedImage = decoder.read();
 raf.close();

Features included in the JDeli PSD Decoder

ColorSpace : RGB, RGBA, CMYK, CMYKA, GrayScale, Indexed and Lab color photoshop images.



Find out how to read and write images files in Java with JDeli:

Read: BufferedImage image = JDeli.read(streamOrFile);

Write: JDeli.write(myBufferedImage, OutputFormat.HEIC, outputStreamOrFile)

Learn more >>

Georgia Ingham Georgia is a Java Developer. She has spoken at lots of conferences. Her hobbies include reading, completing puzzle books and cycling.