Adobe Image Resource Blocks

This article explains how to work with Adobe image resource blocks in Graphics Mill. For general information about metadata, see the Working with Metadata topic.

The Adobe image resource blocks metadata format consists of independent pieces of structured data. Each data piece has an information type defined and consists of the following fields:

  • unique identifier
  • name
  • size of resource data
  • resource data

Resource data format depends on the type of an image resource block. You can find a list of supported types and formats in the Adobe Photoshop File Formats Specification.

Graphics Mill provides the AdobeResourceBlock and AdobeResourceDictionary classes to work with Adobe image resource blocks. The AdobeResourceBlock class allows you to store the following information about an image resource block: name, size, and resource data. The class stores resource data as a binary buffer, but does not include tools for resource data manipulation, so you should parse and construct the data by yourself. The AdobeResourceDictionary class is a collection of AdobeResourceBlock instances. This class is represented by a hash table, which stores instances of the AdobeResourceBlock class and provides access to them with unique identifiers. The identifiers are image resource block types and they are defined in the specification.

Note

Graphics Mill does not perform any validation of the resource data internal structure while encoding. So, you should provide correctly generated AdobeResourceBlock instances. Files containing incorrect Adobe® image resource blocks can produce errors during opening or processing in Adobe® applications.

As mentioned above, Graphics Mill supports Adobe Image Resource Blocks metadata for JPEG and TIFF files. Each file format has a corresponding image reader, a class from the Aurigma.GraphicsMill.Codecs namespace. So, you can use the JpegReader and TiffReader classes to extract metadata. These classes inherit the ImageReader class, which exposes the AdobeResources property. If an image contains Adobe image resource blocks, the property returns AdobeResourceDictionary collection storing image resource blocks, otherwise the property returns null.

There are two ways to write Adobe image resource blocks. Whichever method you choose, you should prepare an AdobeResourceDictionary collection first. The AdobeResourceBlock class represents an Adobe resource block. To add a resource block to the collection, use the MetadataDictionary.Item(Object) property. Then you can set the collection as a value of the TiffWriter.AdobeResources or JpegWriter.AdobeResources property. Or you can use the Bitmap.Save method and set the collection as a value of the TiffSettings.AdobeResources or JpegSettings.AdobeResources property.

The following code removes the thumbnail from Adobe image resource blocks and marks the image as copyrighted. Thumbnail block ID is 0x0409 and copyright flag ID is 0x040A.

C#
using (var reader = new JpegReader(@"Images\in.jpg"))
{
    // Open reader on the file you need to modify metadata for  
    var adobeResources = reader.AdobeResources;
    if (adobeResources == null)
        adobeResources = new AdobeResourceDictionary();

    // Create new adobe image resource block with the required metadata
    var arBlock = new AdobeResourceBlock("Copyright", new byte[] { 1 });
    // Set this block to the item with 0x040A ID (copyright flag)
    adobeResources[0x040A] = arBlock;
    // Remove a block with 0x0409 (thumbnail data)
    adobeResources.Remove(0x0409);

    // Write new image and metadata
    using (var writer = new JpegWriter(@"Images\out.jpg"))
    {
        writer.AdobeResources = adobeResources;
        Pipeline.Run(reader + writer);
    }
}

See Also

Reference

Manual

Other