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


Java IptcReader类代码示例

本文整理汇总了Java中com.drew.metadata.iptc.IptcReader的典型用法代码示例。如果您正苦于以下问题:Java IptcReader类的具体用法?Java IptcReader怎么用?Java IptcReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testDescription_City

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
public void testDescription_City() throws Exception
{
    File iptcFile = new File("Source/com/drew/metadata/iptc/test/withIptc.jpg");
    MetadataReader reader = new IptcReader(iptcFile);
    Metadata metadata = reader.extract();
    assertTrue(metadata.containsDirectory(IptcDirectory.class));
    Directory directory = metadata.getDirectory(IptcDirectory.class);
    assertEquals("City", directory.getDescription(IptcDirectory.TAG_CITY));
}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:10,代码来源:IptcReaderTest.java

示例2: testDescription_Caption

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
public void testDescription_Caption() throws Exception
{
    File iptcFile = new File("Source/com/drew/metadata/iptc/test/withIptc.jpg");
    MetadataReader reader = new IptcReader(iptcFile);
    Metadata metadata = reader.extract();
    assertTrue(metadata.containsDirectory(IptcDirectory.class));
    Directory directory = metadata.getDirectory(IptcDirectory.class);
    assertEquals("Caption", directory.getDescription(IptcDirectory.TAG_CAPTION));
}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:10,代码来源:IptcReaderTest.java

示例3: readMetadata

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
public static Metadata readMetadata(JPEGDecodeParam decodeParam)
{
  final Metadata metadata = new Metadata();

  /*
   * We should only really be seeing Exif in _data[0]... the 2D array exists because markers can
   * theoretically appear multiple times in the file.
   */
  // TODO test this method
  byte[][] exifSegment = decodeParam
      .getMarkerData(JPEGDecodeParam.APP1_MARKER);
  if (exifSegment != null && exifSegment[0].length > 0)
  {
    new ExifReader(exifSegment[0]).extract(metadata);
  }

  // similarly, use only the first IPTC segment
  byte[][] iptcSegment = decodeParam
      .getMarkerData(JPEGDecodeParam.APPD_MARKER);
  if (iptcSegment != null && iptcSegment[0].length > 0)
  {
    new IptcReader(iptcSegment[0]).extract(metadata);
  }

  // NOTE: Unable to utilise JpegReader for the SOF0 frame here, as the
  // decodeParam doesn't contain the byte[]

  // similarly, use only the first Jpeg Comment segment
  byte[][] jpegCommentSegment = decodeParam
      .getMarkerData(JPEGDecodeParam.COMMENT_MARKER);
  if (jpegCommentSegment != null && jpegCommentSegment[0].length > 0)
  {
    new JpegCommentReader(jpegCommentSegment[0]).extract(metadata);
  }

  return metadata;
}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:38,代码来源:JpegMetadataReaderSunUtils.java

示例4: validateMultipleSegmentRead

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
private void validateMultipleSegmentRead(JpegSegmentReader reader) throws JpegProcessingException
{
    byte[] iptcData = reader.readSegment(JpegSegmentReader.SEGMENT_APPD);
    byte[] exifData = reader.readSegment(JpegSegmentReader.SEGMENT_APP1);
    Assert.assertNotNull(iptcData);
    Assert.assertNotNull(exifData);
    Assert.assertTrue("exif data too short", exifData.length > 4);
    // TODO extracting the data doesn't mean anything in this test case...
    Metadata metadata = new Metadata();
    new ExifReader().extract(new ByteArrayReader(exifData), metadata);
    new IptcReader().extract(new ByteArrayReader(iptcData), metadata);
    Assert.assertEquals("Exif", new String(exifData, 0, 4));
}
 
开发者ID:mxbossard,项目名称:metadata-extractor-osgi,代码行数:14,代码来源:JpegSegmentReaderTest.java

示例5: testDescription_Category

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
public void testDescription_Category() throws Exception
{
    File iptcFile = new File("Source/com/drew/metadata/iptc/test/withIptc.jpg");
    MetadataReader reader = new IptcReader(iptcFile);
    Metadata metadata = reader.extract();
    assertTrue(metadata.containsDirectory(IptcDirectory.class));
    Directory directory = metadata.getDirectory(IptcDirectory.class);
    assertEquals("Supl. Category2 Supl. Category1 Cat", directory.getDescription(IptcDirectory.TAG_CATEGORY));
}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:10,代码来源:IptcReaderTest.java

示例6: extractMetadataFromJpegSegmentReader

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
@NotNull
public static Metadata extractMetadataFromJpegSegmentReader(@NotNull JpegSegmentData segmentReader)
{
    final Metadata metadata = new Metadata();

    // Loop through looking for all SOFn segments.  When we find one, we know what type of compression
    // was used for the JPEG, and we can process the JPEG metadata in the segment too.
    for (byte i = 0; i < 16; i++) {
        // There are no SOF4 or SOF12 segments, so don't bother
        if (i == 4 || i == 12)
            continue;
        // Should never have more than one SOFn for a given 'n'.
        byte[] jpegSegment = segmentReader.getSegment((byte)(JpegSegmentReader.SEGMENT_SOF0 + i));
        if (jpegSegment == null)
            continue;
        JpegDirectory directory = metadata.getOrCreateDirectory(JpegDirectory.class);
        directory.setInt(JpegDirectory.TAG_JPEG_COMPRESSION_TYPE, i);
        new JpegReader().extract(new ByteArrayReader(jpegSegment), metadata);
        break;
    }

    // There should never be more than one COM segment.
    byte[] comSegment = segmentReader.getSegment(JpegSegmentReader.SEGMENT_COM);
    if (comSegment != null)
        new JpegCommentReader().extract(new ByteArrayReader(comSegment), metadata);

    // Loop through all APP0 segments, looking for a JFIF segment.
    for (byte[] app0Segment : segmentReader.getSegments(JpegSegmentReader.SEGMENT_APP0)) {
        if (app0Segment.length > 3 && new String(app0Segment, 0, 4).equals("JFIF"))
            new JfifReader().extract(new ByteArrayReader(app0Segment), metadata);
    }

    // Loop through all APP1 segments, checking the leading bytes to identify the format of each.
    for (byte[] app1Segment : segmentReader.getSegments(JpegSegmentReader.SEGMENT_APP1)) {
        if (app1Segment.length > 3 && "EXIF".equalsIgnoreCase(new String(app1Segment, 0, 4)))
            new ExifReader().extract(new ByteArrayReader(app1Segment), metadata);

        if (app1Segment.length > 27 && "http://ns.adobe.com/xap/1.0/".equalsIgnoreCase(new String(app1Segment, 0, 28)))
            new XmpReader().extract(new ByteArrayReader(app1Segment), metadata);
    }

    // Loop through all APP2 segments, looking for something we can process.
    for (byte[] app2Segment : segmentReader.getSegments(JpegSegmentReader.SEGMENT_APP2)) {
        if (app2Segment.length > 10 && new String(app2Segment, 0, 11).equalsIgnoreCase("ICC_PROFILE")) {
            byte[] icc = new byte[app2Segment.length-14];
            System.arraycopy(app2Segment, 14, icc, 0, app2Segment.length-14);
            new IccReader().extract(new ByteArrayReader(icc), metadata);
        }
    }

    // Loop through all APPD segments, checking the leading bytes to identify the format of each.
    for (byte[] appdSegment : segmentReader.getSegments(JpegSegmentReader.SEGMENT_APPD)) {
        if (appdSegment.length > 12 && "Photoshop 3.0".compareTo(new String(appdSegment, 0, 13))==0) {
            new PhotoshopReader().extract(new ByteArrayReader(appdSegment), metadata);
        } else {
            // TODO might be able to check for a leading 0x1c02 for IPTC data...
            new IptcReader().extract(new ByteArrayReader(appdSegment), metadata);
        }
    }

    // Loop through all APPE segments, checking the leading bytes to identify the format of each.
    for (byte[] appeSegment : segmentReader.getSegments(JpegSegmentReader.SEGMENT_APPE)) {
        if (appeSegment.length == 12 && "Adobe".compareTo(new String(appeSegment, 0, 5))==0) {
            new AdobeJpegReader().extract(new ByteArrayReader(appeSegment), metadata);
        }
    }

    return metadata;
}
 
开发者ID:mxbossard,项目名称:metadata-extractor-osgi,代码行数:70,代码来源:JpegMetadataReader.java

示例7: extract

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
public void extract(@NotNull final BufferReader reader, final @NotNull Metadata metadata)
{
    final PhotoshopDirectory directory = metadata.getOrCreateDirectory(PhotoshopDirectory.class);

    int pos = 0;
    try {
        pos = reader.getString(0, 13).equals("Photoshop 3.0") ? 14 : 0;
    } catch (BufferBoundsException e) {
        directory.addError("Unable to read header");
        return;
    }

    while (pos < reader.getLength()) {
        try {
            // 4 bytes for the signature.  Should always be "8BIM".
            //String signature = new String(data, pos, 4);
            pos += 4;

            // 2 bytes for the resource identifier (tag type).
            int tagType = reader.getUInt16(pos); // segment type
            pos += 2;

            // A variable number of bytes holding a pascal string (two leading bytes for length).
            int descriptionLength = reader.getUInt16(pos);
            pos += 2;
            // Some basic bounds checking
            if (descriptionLength < 0 || descriptionLength + pos > reader.getLength())
                return;
            //String description = new String(data, pos, descriptionLength);
            pos += descriptionLength;
            // The number of bytes is padded with a trailing zero, if needed, to make the size even.
            if (pos % 2 != 0)
                pos++;

            // 4 bytes for the size of the resource data that follows.
            int byteCount = reader.getInt32(pos);
            pos += 4;
            // The resource data.
            byte[] tagBytes = reader.getBytes(pos, byteCount);
            pos += byteCount;
            // The number of bytes is padded with a trailing zero, if needed, to make the size even.
            if (pos % 2 != 0)
                pos++;

            directory.setByteArray(tagType, tagBytes);

            // TODO allow rebasing the reader with a new zero-point, rather than copying data here
            if (tagType == PhotoshopDirectory.TAG_PHOTOSHOP_IPTC)
                new IptcReader().extract(new ByteArrayReader(tagBytes), metadata);

            if (tagType >= 0x0fa0 && tagType <= 0x1387)
                PhotoshopDirectory._tagNameMap.put(tagType, String.format("Plug-in %d Data", tagType - 0x0fa0 + 1));
        } catch (BufferBoundsException ex) {
            directory.addError(ex.getMessage());
            return;
        }
    }
}
 
开发者ID:mxbossard,项目名称:metadata-extractor-osgi,代码行数:59,代码来源:PhotoshopReader.java

示例8: validateMultipleSegmentRead

import com.drew.metadata.iptc.IptcReader; //导入依赖的package包/类
private void validateMultipleSegmentRead(JpegSegmentReader reader) throws JpegProcessingException
{
    byte[] iptcData = reader.readSegment(JpegSegmentReader.SEGMENT_APPD);
    byte[] exifData = reader.readSegment(JpegSegmentReader.SEGMENT_APP1);
    assertTrue("exif data too short", exifData.length > 4);
    new ExifReader(exifData).extract();
    new IptcReader(iptcData).extract();
    assertEquals("Exif", new String(exifData, 0, 4));
}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:10,代码来源:JpegSegmentReaderTest.java


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