Example usage for org.apache.commons.imaging.formats.tiff TiffField getByteArrayValue

List of usage examples for org.apache.commons.imaging.formats.tiff TiffField getByteArrayValue

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.tiff TiffField getByteArrayValue.

Prototype

public byte[] getByteArrayValue() 

Source Link

Document

Returns a copy of the raw value of the field.

Usage

From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataReader.java

private byte[] getTagByteValue(final TagInfo aTagInfo) {
    if (jpegMetadata != null) {
        final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(aTagInfo);
        if (field != null) {
            final FieldType fieldType = field.getFieldType();
            if (fieldType.getType() == FieldType.BYTE.getType()) {
                return field.getByteArrayValue();
            }/*from w  w  w .j a v a2 s.com*/
        }
    }
    return null;
}

From source file:net.tourbook.photo.Photo.java

/**
 * GPS area info//w w  w .j  a v a2 s  .  c o m
 */
private String getExifValueGpsArea(final JpegImageMetadata jpegMetadata) {

    try {
        final TiffField field = jpegMetadata
                .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_AREA_INFORMATION);
        if (field != null) {
            final Object fieldValue = field.getValue();
            if (fieldValue != null) {

                /**
                 * source: Exif 2.2 specification
                 * 
                 * <pre>
                 * 
                 * Table 6 Character Codes and their Designation
                 * 
                 * Character Code   Code Designation (8 Bytes)                   References
                 * ASCII           41.H, 53.H, 43.H, 49.H, 49.H, 00.H, 00.H, 00.H  ITU-T T.50 IA5
                 * JIS            A.H, 49.H, 53.H, 00.H, 00.H, 00.H, 00.H, 00.H   JIS X208-1990
                 * Unicode         55.H, 4E.H, 49.H, 43.H, 4F.H, 44.H, 45.H, 00.H  Unicode Standard
                 * Undefined      00.H, 00.H, 00.H, 00.H, 00.H, 00.H, 00.H, 00.H  Undefined
                 * 
                 * </pre>
                 */
                final byte[] byteArrayValue = field.getByteArrayValue();
                final int fieldLength = byteArrayValue.length;

                if (fieldLength > 0) {

                    /**
                     * <pre>
                     * 
                     * skipping 1 + 6 characters:
                     * 
                     * 1      character code
                     * 2...7  have no idea why these bytes are set to none valid characters
                     * 
                     * </pre>
                     */
                    final byte[] valueBytes = Arrays.copyOfRange(byteArrayValue, 7, fieldLength);

                    String valueString = null;

                    final byte firstByte = byteArrayValue[0];
                    if (firstByte == 0x55) {

                        valueString = new String(valueBytes, UI.UTF_16);

                    } else {

                        valueString = new String(valueBytes);
                    }

                    return valueString;
                }
            }
        }
    } catch (final Exception e) {
        // ignore
    }

    return null;
}

From source file:zz.filecollector.fileprocessor.JpgPhotoProcessor.java

@Override
public void extractFileInfo(File file, FileInfo info) {
    FileProcessor.getBasicFileInfo(file, info);
    if (info.getFileType() == FileInfo.UNKNOWN) {
        info.setFileType(FileInfo.PHOTO);
    }//from  w ww .java 2  s .c o m

    try {
        ImageMetadata metadata = Imaging.getMetadata(file);
        if (metadata instanceof JpegImageMetadata) {
            final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;

            if (info.getCreateDate() == null) {
                try {
                    TiffField dateTime = jpegMetadata
                            .findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_DATE_TIME);
                    if (dateTime != null) {
                        String str = dateTime.getStringValue(); // 2014:02:06 12:11:26
                        if (StringUtils.isNotEmpty(str)) {
                            Date date = dateFormat.parse(str);
                            info.setCreateDate(date);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            if (info.getDevice() == null) {
                TiffField model = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL);
                if (model != null) {
                    byte[] bytes = model.getByteArrayValue();
                    String modelStr = new String(bytes).trim();
                    if (StringUtils.isNotEmpty(modelStr)) {
                        info.setDevice(modelStr);
                    }
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}