当前位置: 首页>>代码示例>>Java>>正文


Java Metadata.getOrCreateDirectory方法代码示例

本文整理汇总了Java中com.drew.metadata.Metadata.getOrCreateDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java Metadata.getOrCreateDirectory方法的具体用法?Java Metadata.getOrCreateDirectory怎么用?Java Metadata.getOrCreateDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.drew.metadata.Metadata的用法示例。


在下文中一共展示了Metadata.getOrCreateDirectory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
public void extract(@NotNull SequentialReader reader, @NotNull Metadata metadata)
{
    final Directory directory = metadata.getOrCreateDirectory(AdobeJpegDirectory.class);
    try {
        reader.setMotorolaByteOrder(false);

        if (!reader.getString(5).equals("Adobe")) {
            directory.addError("Invalid Adobe JPEG data header.");
            return;
        }

        directory.setInt(AdobeJpegDirectory.TAG_DCT_ENCODE_VERSION, reader.getUInt16());
        directory.setInt(AdobeJpegDirectory.TAG_APP14_FLAGS0, reader.getUInt16());
        directory.setInt(AdobeJpegDirectory.TAG_APP14_FLAGS1, reader.getUInt16());
        directory.setInt(AdobeJpegDirectory.TAG_COLOR_TRANSFORM, reader.getInt8());
    } catch (IOException ex) {
        directory.addError("IO exception processing data: " + ex.getMessage());
    }
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:20,代码来源:AdobeJpegReader.java

示例2: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
/**
 * Version specifically for dealing with XMP found in JPEG segments. This form of XMP has a peculiar preamble, which
 * must be removed before parsing the XML.
 *
 * @param segmentBytes The byte array from which the metadata should be extracted.
 * @param metadata The {@link Metadata} object into which extracted values should be merged.
 * @param segmentType The {@link JpegSegmentType} being read.
 */
public void extract(@NotNull byte[] segmentBytes, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
{
    XmpDirectory directory = metadata.getOrCreateDirectory(XmpDirectory.class);

    // XMP in a JPEG file has a 29 byte preamble which is not valid XML.
    final int preambleLength = 29;

    // check for the header length
    if (segmentBytes.length <= preambleLength + 1) {
        directory.addError(String.format("Xmp data segment must contain at least %d bytes", preambleLength + 1));
        return;
    }

    ByteArrayReader reader = new ByteArrayReader(segmentBytes);

    String preamble = new String(segmentBytes, 0, preambleLength);
    if (!"http://ns.adobe.com/xap/1.0/\0".equals(preamble)) {
        directory.addError("XMP data segment doesn't begin with 'http://ns.adobe.com/xap/1.0/'");
        return;
    }

    byte[] xmlBytes = new byte[segmentBytes.length - preambleLength];
    System.arraycopy(segmentBytes, 29, xmlBytes, 0, xmlBytes.length);
    extract(xmlBytes, metadata);
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:34,代码来源:XmpReader.java

示例3: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
/**
 * Performs the Jfif data extraction, adding found values to the specified
 * instance of {@link Metadata}.
 */
public void extract(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata)
{
    JfifDirectory directory = metadata.getOrCreateDirectory(JfifDirectory.class);

    try {
        // For JFIF, the tag number is also the offset into the segment

        int ver = reader.getUInt16(JfifDirectory.TAG_VERSION);
        directory.setInt(JfifDirectory.TAG_VERSION, ver);

        int units = reader.getUInt8(JfifDirectory.TAG_UNITS);
        directory.setInt(JfifDirectory.TAG_UNITS, units);

        int height = reader.getUInt16(JfifDirectory.TAG_RESX);
        directory.setInt(JfifDirectory.TAG_RESX, height);

        int width = reader.getUInt16(JfifDirectory.TAG_RESY);
        directory.setInt(JfifDirectory.TAG_RESY, width);

    } catch (IOException me) {
        directory.addError(me.getMessage());
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:28,代码来源:JfifReader.java

示例4: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
public void extract(@NotNull byte[] segmentBytes, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
{
    JpegCommentDirectory directory = metadata.getOrCreateDirectory(JpegCommentDirectory.class);

    // The entire contents of the directory are the comment
    directory.setString(JpegCommentDirectory.TAG_COMMENT, new String(segmentBytes));
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:8,代码来源:JpegCommentReader.java

示例5: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
public void extract(@NotNull byte[] segmentBytes, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
{
    if (metadata.containsDirectory(JpegDirectory.class)) {
        // If this directory is already present, discontinue this operation.
        // We only store metadata for the *first* matching SOFn segment.
        return;
    }

    JpegDirectory directory = metadata.getOrCreateDirectory(JpegDirectory.class);

    // The value of TAG_COMPRESSION_TYPE is determined by the segment type found
    directory.setInt(JpegDirectory.TAG_COMPRESSION_TYPE, segmentType.byteValue - JpegSegmentType.SOF0.byteValue);

    SequentialReader reader = new SequentialByteArrayReader(segmentBytes);

    try {
        directory.setInt(JpegDirectory.TAG_DATA_PRECISION, reader.getUInt8());
        directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16());
        directory.setInt(JpegDirectory.TAG_IMAGE_WIDTH, reader.getUInt16());
        short componentCount = reader.getUInt8();
        directory.setInt(JpegDirectory.TAG_NUMBER_OF_COMPONENTS, componentCount);

        // for each component, there are three bytes of data:
        // 1 - Component ID: 1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q
        // 2 - Sampling factors: bit 0-3 vertical, 4-7 horizontal
        // 3 - Quantization table number
        for (int i = 0; i < (int)componentCount; i++) {
            final int componentId = reader.getUInt8();
            final int samplingFactorByte = reader.getUInt8();
            final int quantizationTableNumber = reader.getUInt8();
            final JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
            directory.setObject(JpegDirectory.TAG_COMPONENT_DATA_1 + i, component);
        }

    } catch (IOException ex) {
        directory.addError(ex.getMessage());
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:39,代码来源:JpegReader.java

示例6: extractTiff

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
/**
 * Performs the Exif data extraction on a TIFF/RAW, adding found values to the specified
 * instance of {@link Metadata}.
 *
 * @param reader   The {@link RandomAccessReader} from which TIFF data should be read.
 * @param metadata The Metadata object into which extracted values should be merged.
 */
@Deprecated
public void extractTiff(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata)
{
    final ExifIFD0Directory directory = metadata.getOrCreateDirectory(ExifIFD0Directory.class);

    try {
        extractTiff(reader, metadata, directory, 0);
    } catch (IOException e) {
        directory.addError("IO problem: " + e.getMessage());
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:19,代码来源:ExifReader.java

示例7: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
public void extract(@NotNull final SequentialReader reader, final @NotNull Metadata metadata)
{
    final GifHeaderDirectory directory = metadata.getOrCreateDirectory(GifHeaderDirectory.class);

    // FILE HEADER
    //
    // 3 - signature: "GIF"
    // 3 - version: either "87a" or "89a"
    //
    // LOGICAL SCREEN DESCRIPTOR
    //
    // 2 - pixel width
    // 2 - pixel height
    // 1 - screen and color map information flags (0 is LSB)
    //       0-2  Size of the global color table
    //       3    Color table sort flag (89a only)
    //       4-6  Color resolution
    //       7    Global color table flag
    // 1 - background color index
    // 1 - pixel aspect ratio

    reader.setMotorolaByteOrder(false);

    try {
        String signature = reader.getString(3);

        if (!signature.equals("GIF"))
        {
            directory.addError("Invalid GIF file signature");
            return;
        }

        String version = reader.getString(3);

        if (!version.equals(GIF_87A_VERSION_IDENTIFIER) && !version.equals(GIF_89A_VERSION_IDENTIFIER)) {
            directory.addError("Unexpected GIF version");
            return;
        }

        directory.setString(GifHeaderDirectory.TAG_GIF_FORMAT_VERSION, version);
        directory.setInt(GifHeaderDirectory.TAG_IMAGE_WIDTH, reader.getUInt16());
        directory.setInt(GifHeaderDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16());

        short flags = reader.getUInt8();

        // First three bits = (BPP - 1)
        int colorTableSize = 1 << ((flags & 7) + 1);
        directory.setInt(GifHeaderDirectory.TAG_COLOR_TABLE_SIZE, colorTableSize);

        if (version.equals(GIF_89A_VERSION_IDENTIFIER)) {
            boolean isColorTableSorted = (flags & 8) != 0;
            directory.setBoolean(GifHeaderDirectory.TAG_IS_COLOR_TABLE_SORTED, isColorTableSorted);
        }

        int bitsPerPixel = ((flags & 0x70) >> 4) + 1;
        directory.setInt(GifHeaderDirectory.TAG_BITS_PER_PIXEL, bitsPerPixel);

        boolean hasGlobalColorTable = (flags & 0xf) != 0;
        directory.setBoolean(GifHeaderDirectory.TAG_HAS_GLOBAL_COLOR_TABLE, hasGlobalColorTable);

        directory.setInt(GifHeaderDirectory.TAG_TRANSPARENT_COLOR_INDEX, reader.getUInt8());

        int aspectRatioByte = reader.getUInt8();
        if (aspectRatioByte != 0) {
            float pixelAspectRatio = (float)((aspectRatioByte + 15d) / 64d);
            directory.setFloat(GifHeaderDirectory.TAG_PIXEL_ASPECT_RATIO, pixelAspectRatio);
        }

    } catch (IOException e) {
        directory.addError("Unable to read BMP header");
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:73,代码来源:GifReader.java

示例8: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
public void extract(@NotNull final RandomAccessReader reader, final @NotNull Metadata metadata)
{
    final PsdHeaderDirectory directory = metadata.getOrCreateDirectory(PsdHeaderDirectory.class);

    try {
        final int signature = reader.getInt32(0);
        if (signature != 0x38425053)
        {
            directory.addError("Invalid PSD file signature");
            return;
        }

        final int version = reader.getUInt16(4);
        if (version != 1 && version != 2)
        {
            directory.addError("Invalid PSD file version (must be 1 or 2)");
            return;
        }

        // 6 reserved bytes are skipped here.  They should be zero.

        final int channelCount = reader.getUInt16(12);
        directory.setInt(PsdHeaderDirectory.TAG_CHANNEL_COUNT, channelCount);

        // even though this is probably an unsigned int, the max height in practice is 300,000
        final int imageHeight = reader.getInt32(14);
        directory.setInt(PsdHeaderDirectory.TAG_IMAGE_HEIGHT, imageHeight);

        // even though this is probably an unsigned int, the max width in practice is 300,000
        final int imageWidth = reader.getInt32(18);
        directory.setInt(PsdHeaderDirectory.TAG_IMAGE_WIDTH, imageWidth);

        final int bitsPerChannel = reader.getUInt16(22);
        directory.setInt(PsdHeaderDirectory.TAG_BITS_PER_CHANNEL, bitsPerChannel);

        final int colorMode = reader.getUInt16(24);
        directory.setInt(PsdHeaderDirectory.TAG_COLOR_MODE, colorMode);
    } catch (IOException e) {
        directory.addError("Unable to read PSD header");
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:42,代码来源:PsdReader.java

示例9: extract

import com.drew.metadata.Metadata; //导入方法依赖的package包/类
public void extract(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata)
{
    // TODO review whether the 'tagPtr' values below really do require ICC processing to work with a RandomAccessReader

    final IccDirectory directory = metadata.getOrCreateDirectory(IccDirectory.class);

    try {
        directory.setInt(IccDirectory.TAG_PROFILE_BYTE_COUNT, reader.getInt32(IccDirectory.TAG_PROFILE_BYTE_COUNT));

        // For these tags, the int value of the tag is in fact it's offset within the buffer.
        set4ByteString(directory, IccDirectory.TAG_CMM_TYPE, reader);
        setInt32(directory, IccDirectory.TAG_PROFILE_VERSION, reader);
        set4ByteString(directory, IccDirectory.TAG_PROFILE_CLASS, reader);
        set4ByteString(directory, IccDirectory.TAG_COLOR_SPACE, reader);
        set4ByteString(directory, IccDirectory.TAG_PROFILE_CONNECTION_SPACE, reader);
        setDate(directory, IccDirectory.TAG_PROFILE_DATETIME, reader);
        set4ByteString(directory, IccDirectory.TAG_SIGNATURE, reader);
        set4ByteString(directory, IccDirectory.TAG_PLATFORM, reader);
        setInt32(directory, IccDirectory.TAG_CMM_FLAGS, reader);
        set4ByteString(directory, IccDirectory.TAG_DEVICE_MAKE, reader);

        int temp = reader.getInt32(IccDirectory.TAG_DEVICE_MODEL);
        if (temp != 0) {
            if (temp <= 0x20202020) {
                directory.setInt(IccDirectory.TAG_DEVICE_MODEL, temp);
            } else {
                directory.setString(IccDirectory.TAG_DEVICE_MODEL, getStringFromInt32(temp));
            }
        }

        setInt32(directory, IccDirectory.TAG_RENDERING_INTENT, reader);
        setInt64(directory, IccDirectory.TAG_DEVICE_ATTR, reader);

        float[] xyz = new float[]{
                reader.getS15Fixed16(IccDirectory.TAG_XYZ_VALUES),
                reader.getS15Fixed16(IccDirectory.TAG_XYZ_VALUES + 4),
                reader.getS15Fixed16(IccDirectory.TAG_XYZ_VALUES + 8)
        };
        directory.setObject(IccDirectory.TAG_XYZ_VALUES, xyz);

        // Process 'ICC tags'
        int tagCount = reader.getInt32(IccDirectory.TAG_TAG_COUNT);
        directory.setInt(IccDirectory.TAG_TAG_COUNT, tagCount);

        for (int i = 0; i < tagCount; i++) {
            int pos = IccDirectory.TAG_TAG_COUNT + 4 + i * 12;
            int tagType = reader.getInt32(pos);
            int tagPtr = reader.getInt32(pos + 4);
            int tagLen = reader.getInt32(pos + 8);
            byte[] b = reader.getBytes(tagPtr, tagLen);
            directory.setByteArray(tagType, b);
        }
    } catch (IOException ex) {
        directory.addError("Exception reading ICC profile: " + ex.getMessage());
    }
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:57,代码来源:IccReader.java


注:本文中的com.drew.metadata.Metadata.getOrCreateDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。