}
public TiffOutputDirectory getOutputDirectory(final ByteOrder byteOrder)
throws ImageWriteException {
try {
final TiffOutputDirectory dstDir = new TiffOutputDirectory(type,
byteOrder);
final List<? extends IImageMetadataItem> entries = getItems();
for (IImageMetadataItem entry : entries) {
final TiffImageMetadata.Item item = (TiffImageMetadata.Item) entry;
final TiffField srcField = item.getTiffField();
if (null != dstDir.findField(srcField.getTag())) {
// ignore duplicate tags in a directory.
continue;
} else if (srcField.getTagInfo().isOffset()) {
// ignore offset fields.
continue;
}
final TagInfo tagInfo = srcField.getTagInfo();
final FieldType fieldType = srcField.getFieldType();
// byte bytes[] = srcField.fieldType.getRawBytes(srcField);
// Debug.debug("tagInfo", tagInfo);
final Object value = srcField.getValue();
// Debug.debug("value", Debug.getType(value));
final byte[] bytes = tagInfo.encodeValue(fieldType, value,
byteOrder);
// if (tagInfo.isUnknown())
// Debug.debug(
// "\t" + "unknown tag(0x"
// + Integer.toHexString(srcField.tag)
// + ") bytes", bytes);
final int count = bytes.length / fieldType.getSize();
final TiffOutputField dstField = new TiffOutputField(
srcField.getTag(), tagInfo, fieldType, count, bytes);
dstField.setSortHint(srcField.getSortHint());
dstDir.add(dstField);
}
dstDir.setTiffImageData(getTiffImageData());
dstDir.setJpegImageData(getJpegImageData());
return dstDir;
} catch (final ImageReadException e) {
throw new ImageWriteException(e.getMessage(), e);
}