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


Java Directory.containsTag方法代码示例

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


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

示例1: getExifDate

import com.drew.metadata.Directory; //导入方法依赖的package包/类
/**
 *
 * @param filePath
 * @return
 */
private String getExifDate(File file) {

  try {
    Metadata metadata = ImageMetadataReader.readMetadata(file);
    Directory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
    int dateTag = ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL;

    if (directory != null && directory.containsTag(dateTag)) {
      Date date = directory.getDate(dateTag, TimeZone.getDefault());
      return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
    } else {
      return "";
    }
  } catch (ImageProcessingException | IOException ex) {
    LOGGER.log(Level.INFO, 
        "Exif error for {0}: {1}",
        new String[]{file.getName(), ex.getLocalizedMessage()}
    );
    return "";
  }
}
 
开发者ID:yarl,项目名称:pattypan,代码行数:27,代码来源:CreateFilePane.java

示例2: handle

import com.drew.metadata.Directory; //导入方法依赖的package包/类
public void handle(Directory directory, Metadata metadata)
        throws MetadataException {
    if (directory.containsTag(IptcDirectory.TAG_KEYWORDS)) {
        String[] keywords = directory.getStringArray(IptcDirectory.TAG_KEYWORDS);
        for (String k : keywords) {
            metadata.add(TikaCoreProperties.KEYWORDS, k);
        }
    }
    if (directory.containsTag(IptcDirectory.TAG_HEADLINE)) {
        metadata.set(TikaCoreProperties.TITLE, directory.getString(IptcDirectory.TAG_HEADLINE));
    } else if (directory.containsTag(IptcDirectory.TAG_OBJECT_NAME)) {
        metadata.set(TikaCoreProperties.TITLE, directory.getString(IptcDirectory.TAG_OBJECT_NAME));
    }
    if (directory.containsTag(IptcDirectory.TAG_BY_LINE)) {
        metadata.set(TikaCoreProperties.CREATOR, directory.getString(IptcDirectory.TAG_BY_LINE));
        metadata.set(IPTC.CREATOR, directory.getString(IptcDirectory.TAG_BY_LINE));
    }
    if (directory.containsTag(IptcDirectory.TAG_CAPTION)) {
        metadata.set(TikaCoreProperties.DESCRIPTION,
                // Looks like metadata extractor returns IPTC newlines as a single carriage return,
                // but the exiv2 command does not so we change to line feed here because that is less surprising to users                        
                directory.getString(IptcDirectory.TAG_CAPTION).replaceAll("\r\n?", "\n"));
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:25,代码来源:ImageMetadataExtractor.java

示例3: handleExifIFD0Directory

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private void handleExifIFD0Directory(MetaData metaData, Directory directory) throws MetadataException{
	
	metaData.put(Image.MetaName.Make, getStringValue(directory, ExifIFD0Directory.TAG_MAKE));
	metaData.put(Image.MetaName.Model, getStringValue(directory, ExifIFD0Directory.TAG_MODEL));
	metaData.put(Image.MetaName.Software, getStringValue(directory, ExifIFD0Directory.TAG_SOFTWARE));

	// Date/Time Original overrides value from ExifDirectory.TAG_DATETIME
	// Unless we have GPS time we don't know the time zone so date must be set
	// as ISO 8601 datetime without timezone suffix (no Z or +/-)
	if (directory.containsTag(ExifIFD0Directory.TAG_DATETIME)) {
		metaData.put(Image.MetaName.DateTimeOriginal, getDateValue(directory, ExifIFD0Directory.TAG_DATETIME));
	}		

	if (directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)){
		Integer val = getIntValue(directory, ExifIFD0Directory.TAG_ORIENTATION);
		metaData.put(Image.MetaName.Orientation, translateOrientation(val));
	}

}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:20,代码来源:ExifMetaDataPaser.java

示例4: getStringValue

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private static String getStringValue(Directory exifDirectory, int tagType) {
	if (exifDirectory.containsTag(tagType)) {
		return exifDirectory.getString(tagType);
	}else{
		return null;
	}
}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:8,代码来源:ExifMetaDataPaser.java

示例5: getDateValue

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private static Date getDateValue(Directory exifDirectory, int tagType) throws MetadataException {
	if (exifDirectory.containsTag(tagType)) {
		return exifDirectory.getDate(tagType);
	}else{
		return null;
	}
}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:8,代码来源:ExifMetaDataPaser.java

示例6: getIntValue

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private static Integer getIntValue(Directory exifDirectory, int tagType) throws MetadataException {
	if (exifDirectory.containsTag(tagType)) {
		return exifDirectory.getInt(tagType);
	}else{
		return null;
	}
}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:8,代码来源:ExifMetaDataPaser.java

示例7: getDegree

import com.drew.metadata.Directory; //导入方法依赖的package包/类
/**
 * only for GPS directory.
 * HoursMinutesSeconds see
 * http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-008-2010_E.pdf
 *
 * @param tagType
 * @return
 * @throws MetadataException
 */
private static Float getDegree(Directory gpsDirectory, int tagType) throws MetadataException {
	if (gpsDirectory.containsTag(tagType)){
		Rational[] components = gpsDirectory.getRationalArray(tagType);
		int deg = components[0].intValue();
		float min = components[1].floatValue();
		float sec = components[2].floatValue();
		return (float) deg + (min + sec / 60F) / 60F;
	}else{
		return null;
	}
}
 
开发者ID:ivarptr,项目名称:clobaframe,代码行数:21,代码来源:ExifMetaDataPaser.java

示例8: processTag

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private void processTag(@NotNull SequentialReader reader, @NotNull Directory directory, int directoryType, int tagType, int tagByteCount) throws IOException
{
    int tagIdentifier = tagType | (directoryType << 8);

    String string = null;

    switch (tagIdentifier) {
        case IptcDirectory.TAG_APPLICATION_RECORD_VERSION:
            // short
            int shortValue = reader.getUInt16();
            reader.skip(tagByteCount - 2);
            directory.setInt(tagIdentifier, shortValue);
            return;
        case IptcDirectory.TAG_URGENCY:
            // byte
            directory.setInt(tagIdentifier, reader.getUInt8());
            reader.skip(tagByteCount - 1);
            return;
        case IptcDirectory.TAG_RELEASE_DATE:
        case IptcDirectory.TAG_DATE_CREATED:
            // Date object
            if (tagByteCount >= 8) {
                string = reader.getString(tagByteCount);
                try {
                    int year = Integer.parseInt(string.substring(0, 4));
                    int month = Integer.parseInt(string.substring(4, 6)) - 1;
                    int day = Integer.parseInt(string.substring(6, 8));
                    Date date = new java.util.GregorianCalendar(year, month, day).getTime();
                    directory.setDate(tagIdentifier, date);
                    return;
                } catch (NumberFormatException e) {
                    // fall through and we'll process the 'string' value below
                }
            } else {
                reader.skip(tagByteCount);
            }
        case IptcDirectory.TAG_RELEASE_TIME:
        case IptcDirectory.TAG_TIME_CREATED:
            // time...
        default:
            // fall through
    }

    // If we haven't returned yet, treat it as a string
    // NOTE that there's a chance we've already loaded the value as a string above, but failed to parse the value
    if (string == null) {
        string = reader.getString(tagByteCount, System.getProperty("file.encoding")); // "ISO-8859-1"
    }

    if (directory.containsTag(tagIdentifier)) {
        // this fancy string[] business avoids using an ArrayList for performance reasons
        String[] oldStrings = directory.getStringArray(tagIdentifier);
        String[] newStrings;
        if (oldStrings == null) {
            newStrings = new String[1];
        } else {
            newStrings = new String[oldStrings.length + 1];
            System.arraycopy(oldStrings, 0, newStrings, 0, oldStrings.length);
        }
        newStrings[newStrings.length - 1] = string;
        directory.setStringArray(tagIdentifier, newStrings);
    } else {
        directory.setString(tagIdentifier, string);
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:66,代码来源:IptcReader.java

示例9: processTag

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private void processTag(@NotNull BufferReader reader, @NotNull Directory directory, int directoryType, int tagType, int offset, int tagByteCount) throws BufferBoundsException
{
    int tagIdentifier = tagType | (directoryType << 8);

    switch (tagIdentifier) {
        case IptcDirectory.TAG_APPLICATION_RECORD_VERSION:
            // short
            int shortValue = reader.getUInt16(offset);
            directory.setInt(tagIdentifier, shortValue);
            return;
        case IptcDirectory.TAG_URGENCY:
            // byte
            directory.setInt(tagIdentifier, reader.getUInt8(offset));
            return;
        case IptcDirectory.TAG_RELEASE_DATE:
        case IptcDirectory.TAG_DATE_CREATED:
            // Date object
            if (tagByteCount >= 8) {
                String dateStr = reader.getString(offset, tagByteCount);
                try {
                    int year = Integer.parseInt(dateStr.substring(0, 4));
                    int month = Integer.parseInt(dateStr.substring(4, 6)) - 1;
                    int day = Integer.parseInt(dateStr.substring(6, 8));
                    Date date = new java.util.GregorianCalendar(year, month, day).getTime();
                    directory.setDate(tagIdentifier, date);
                    return;
                } catch (NumberFormatException e) {
                    // fall through and we'll store whatever was there as a String
                }
            }
        case IptcDirectory.TAG_RELEASE_TIME:
        case IptcDirectory.TAG_TIME_CREATED:
            // time...
        default:
            // fall through
    }

    // If we haven't returned yet, treat it as a string
    String str;
    if (tagByteCount < 1) {
        str = "";
    } else {
        str = reader.getString(offset, tagByteCount, System.getProperty("file.encoding")); // "ISO-8859-1"
    }

    if (directory.containsTag(tagIdentifier)) {
        // this fancy string[] business avoids using an ArrayList for performance reasons
        String[] oldStrings = directory.getStringArray(tagIdentifier);
        String[] newStrings;
        if (oldStrings == null) {
            newStrings = new String[1];
        } else {
            newStrings = new String[oldStrings.length + 1];
            System.arraycopy(oldStrings, 0, newStrings, 0, oldStrings.length);
        }
        newStrings[newStrings.length - 1] = str;
        directory.setStringArray(tagIdentifier, newStrings);
    } else {
        directory.setString(tagIdentifier, str);
    }
}
 
开发者ID:mxbossard,项目名称:metadata-extractor-osgi,代码行数:62,代码来源:IptcReader.java

示例10: set

import com.drew.metadata.Directory; //导入方法依赖的package包/类
private void set(Directory directory, Metadata metadata, int extractTag, Property metadataField) {
    if (directory.containsTag(extractTag)) {
        Matcher m = LEADING_NUMBERS.matcher(directory.getString(extractTag));
        if(m.matches()) {
            metadata.set(metadataField, m.group(1));
        }
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:9,代码来源:ImageMetadataExtractor.java

示例11: handleCommentTags

import com.drew.metadata.Directory; //导入方法依赖的package包/类
/**
 * EXIF may contain image description, although with undefined encoding.
 * Use IPTC for other annotation fields, and XMP for unicode support.
 */
public void handleCommentTags(Directory directory, Metadata metadata) {
    if (metadata.get(TikaCoreProperties.DESCRIPTION) == null &&
            directory.containsTag(ExifIFD0Directory.TAG_IMAGE_DESCRIPTION)) {
        metadata.set(TikaCoreProperties.DESCRIPTION, 
                directory.getString(ExifIFD0Directory.TAG_IMAGE_DESCRIPTION));
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:12,代码来源:ImageMetadataExtractor.java


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