Resources

Overview

A PSD file stores image resources in its Image Resources section. PsdImage.getImageResources() returns them as an array of ResourceBlock. On the test files of the library this gives 26 blocks for basic-rgb.psd and 28 for resources.psd. Treat the blocks as read-only data: PsdImage.setImageResources always throws UnsupportedOperationException, and getImageResources() returns a new array of new block objects on every call, so changing one block does not change the image.


ResourceBlock

ResourceBlock represents one image resource block. It has getId(), getName(), getSignature(), getSize() and getDataSize(), and declares save(OutputStream). The blocks that getImageResources() returns are PreservedResourceBlock objects, and their save(OutputStream) always throws UnsupportedOperationException. PreservedResourceBlock adapts a raw-preserved resource to the ResourceBlock surface.


The Resource Classes

ClassRole
ResourceBlockThe public base type of an image resource block
PreservedResourceBlockAdapts a raw-preserved resource to the ResourceBlock surface
UnknownResourceA parsed resource block without any ID-specific meaning; keeps its id, name and raw data
PsdResourceInfoA read-only summary of one parsed resource: id, name, kind and data length
PsdResourceKindClassifies a resource: Unknown, GlobalAngle, IccProfile or IccUntaggedProfile
IndexedColorPalette, IndexedColorPaletteInfoThe palette of an indexed-color document, as colors
ImageResourceIdsCommon resource identifiers

Most of these classes are building blocks that the loader and writer use. Your code normally works with the ResourceBlock array that PsdImage.getImageResources() returns.


Tips and Best Practices

  • Treat the resource array as read-only.
  • Use getId() to find the block you want; ids are the identifiers that the PSD format defines.

Common Issues

IssueCauseFix
UnsupportedOperationException from setImageResourcesReplacing resources is not supported in this editionDo not replace resources; edit layer metadata instead
Setting an id on a block has no effect on the imagegetImageResources() returns new block objects each timeTreat blocks as read-only

FAQ

Can I add or remove an image resource?

Not through the public API of this edition.


API Reference Summary

ClassDescription
ResourceBlockAn image resource block
PreservedResourceBlockA raw-preserved resource block
UnknownResourceA resource block without specific meaning
PsdResourceKindThe resource classification
IndexedColorPaletteAn indexed-color palette

See Also