本文整理汇总了Java中com.drew.metadata.Tag类的典型用法代码示例。如果您正苦于以下问题:Java Tag类的具体用法?Java Tag怎么用?Java Tag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tag类属于com.drew.metadata包,在下文中一共展示了Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printImageTags
import com.drew.metadata.Tag; //导入依赖的package包/类
/**
* 读取照片里面的信息
*/
private static void printImageTags(File file) throws Exception {
Metadata metadata = ImageMetadataReader.readMetadata(file);
String createDate = null;
String lat = null;
String lon = null;
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
String tagName = tag.getTagName(); //标签名
String desc = tag.getDescription(); //标签信息
switch (tagName) {
case "Date/Time Original":
createDate = desc.split(" ")[0].replace(":", "-");
break;
case "GPS Latitude":
lat = desc;
break;
case "GPS Longitude":
lon = desc;
break;
}
}
}
moveFile(newFilePath, getposition(pointToLatlong(lat), pointToLatlong(lon)), file, createDate);
}
示例2: metaDataMenuItemActionPerformed
import com.drew.metadata.Tag; //导入依赖的package包/类
private void metaDataMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_metaDataMenuItemActionPerformed
if (openedFile == null) {
return;
}
try {
Metadata metadata = ImageMetadataReader.readMetadata(openedFile);
String metaData = "";
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
metaData += tag + "\n";
}
}
alert(metaData, "Meta Data");
System.out.println("Courtesy: " +
"https://github.com/drewnoakes/metadata-extractor");
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: readExif
import com.drew.metadata.Tag; //导入依赖的package包/类
private static HashMap<String, String> readExif(File file) throws ImageProcessingException, IOException {
HashMap<String, String> map = new HashMap<String, String>();
InputStream is = null;
is = new FileInputStream(file);
Metadata metadata = ImageMetadataReader.readMetadata(is);
Iterable<Directory> iterable = metadata.getDirectories();
for (Iterator<Directory> iter = iterable.iterator(); iter.hasNext();) {
Directory dr = iter.next();
Collection<Tag> tags = dr.getTags();
for (Tag tag : tags)
map.put(tag.getTagName(), tag.getDescription());
}
_tracer.debug("Got Exif. " + file.getAbsolutePath() + "\r\n" + map.toString());
is.close();
return map;
}
示例4: handle
import com.drew.metadata.Tag; //导入依赖的package包/类
public void handle(Directory directory, Metadata metadata)
throws MetadataException {
if (directory.getTags() != null) {
Iterator<?> tags = directory.getTags().iterator();
while (tags.hasNext()) {
Tag tag = (Tag) tags.next();
String name = tag.getTagName();
if (!MetadataFields.isMetadataField(name) && tag.getDescription() != null) {
String value = tag.getDescription().trim();
if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
value = Boolean.TRUE.toString();
} else if (Boolean.FALSE.toString().equalsIgnoreCase(value)) {
value = Boolean.FALSE.toString();
}
metadata.set(name, value);
}
}
}
}
示例5: getOrientation
import com.drew.metadata.Tag; //导入依赖的package包/类
private String getOrientation(ImageFile src) {
try {
Metadata metadata = ImageMetadataReader.readMetadata(src.getInputStream());
Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
if (directory != null) {
for (Tag tag : directory.getTags()) {
if ("Orientation".equals(tag.getTagName())) {
return tag.getDescription();
}
}
}
} catch (IOException|ImageProcessingException e) {
logger.error("Image orientation error", e);
}
return "";
}
示例6: onExtractionSuccess
import com.drew.metadata.Tag; //导入依赖的package包/类
@Override
public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log)
{
super.onExtractionSuccess(file, metadata, relativePath, log);
// Iterate through all values, calling toString to flush out any formatting exceptions
for (Directory directory : metadata.getDirectories()) {
directory.getName();
for (Tag tag : directory.getTags()) {
tag.getTagName();
tag.getDescription();
}
}
}
示例7: onExtracted
import com.drew.metadata.Tag; //导入依赖的package包/类
@Override
public void onExtracted(@NotNull File file, @NotNull Metadata metadata)
{
super.onExtracted(file, metadata);
// Iterate through all values, calling toString to flush out any formatting exceptions
for (Directory directory : metadata.getDirectories()) {
directory.getName();
for (Tag tag : directory.getTags()) {
tag.getTagName();
tag.getDescription();
}
}
}
示例8: MetadataProcessor
import com.drew.metadata.Tag; //导入依赖的package包/类
public MetadataProcessor(File imageFile) {
this.imageFile = imageFile;
try {
data = ImageMetadataReader.readMetadata(imageFile);
} catch (Exception ex) {
Logger.getLogger(MetadataProcessor.class.getName()).log(Level.SEVERE, null, ex);
}
for (Directory directory : data.getDirectories()) {
extracted_data += String.format("----------------------------------------------%15s---------------------------------\n", directory.getName());
for (Tag tag : directory.getTags()) {
extracted_data += tag + "\n";
}
if (directory.hasErrors()) {
for (String error : directory.getErrors()) {
System.err.println("ERROR: " + error);
}
}
}
}
示例9: main
import com.drew.metadata.Tag; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
String path = "J:\\照片2015\\CemareHanHan\\IMG_3480.jpg";
File jpegFile = new File(path);
Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
Directory exif = metadata.getDirectory(ExifIFD0Directory.class);
///下面就是怎么获取属性了
Iterator tags = exif.getTags().iterator(); //getTagIterator();
while (tags.hasNext()) {
Tag tag = (Tag)tags.next();
System.out.println(tag.getTagName() + " ==> " + tag.getDescription());
}
///获取拍摄时间
System.out.println(getShootTime(path));
}
示例10: testRead
import com.drew.metadata.Tag; //导入依赖的package包/类
@Test public void testRead() throws Exception
{
final byte[] jfifData = new byte[] {
74,70,73,70,0,
1,2,
1,
0,108,
0,108,
0,0
};
final Metadata metadata = new Metadata();
final JfifReader reader = new JfifReader();
reader.extract(new ByteArrayReader(jfifData), metadata);
assertEquals(1, metadata.getDirectoryCount());
JfifDirectory directory = metadata.getDirectory(JfifDirectory.class);
assertNotNull(directory);
assertFalse(directory.getErrors().toString(), directory.hasErrors());
Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
assertEquals(4, tags.length);
assertEquals(JfifDirectory.TAG_VERSION, tags[0].getTagType());
assertEquals(0x0102, directory.getInt(tags[0].getTagType()));
assertEquals(JfifDirectory.TAG_UNITS, tags[1].getTagType());
assertEquals(1, directory.getInt(tags[1].getTagType()));
assertEquals(JfifDirectory.TAG_RESX, tags[2].getTagType());
assertEquals(108, directory.getInt(tags[2].getTagType()));
assertEquals(JfifDirectory.TAG_RESY, tags[3].getTagType());
assertEquals(108, directory.getInt(tags[3].getTagType()));
}
示例11: outputMetadata
import com.drew.metadata.Tag; //导入依赖的package包/类
private static void outputMetadata(ContentHandlerHelper helper, Metadata metadata, String elementName) throws MetadataException {
if (metadata.getDirectoryCount() > 0) {
for (Iterator j = metadata.getDirectoryIterator(); j.hasNext();) {
Directory directory = (Directory) j.next();
helper.startElement(elementName, new String[]{"name", directory.getName()});
for (Iterator k = directory.getTagIterator(); k.hasNext();) {
Tag tag = (Tag) k.next();
helper.startElement(TAG_ELEMENT);
helper.element("id", tag.getTagType());
helper.element("name", tag.getTagName());
helper.element("value", tag.getDescription());
helper.endElement();
}
// TODO: Should do something with this?
if (directory.hasErrors()) {
for (Iterator k = directory.getErrors(); k.hasNext();) {
//System.out.println("ERROR: " + k.next());
}
}
helper.endElement();
}
}
}
示例12: testIptc1BytesFromFile
import com.drew.metadata.Tag; //导入依赖的package包/类
@Test
public void testIptc1BytesFromFile() throws Exception
{
IptcDirectory directory = processBytes("Tests/Data/iptc1.jpg.appd");
assertFalse(directory.getErrors().toString(), directory.hasErrors());
Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
assertEquals(16, tags.length);
assertEquals(IptcDirectory.TAG_CATEGORY, tags[0].getTagType());
assertArrayEquals(new String[] { "Supl. Category2", "Supl. Category1", "Cat" }, directory.getStringArray(tags[0].getTagType()));
assertEquals(IptcDirectory.TAG_COPYRIGHT_NOTICE, tags[1].getTagType());
assertEquals("Copyright", directory.getString(tags[1].getTagType()));
assertEquals(IptcDirectory.TAG_SPECIAL_INSTRUCTIONS, tags[2].getTagType());
assertEquals("Special Instr.", directory.getString(tags[2].getTagType()));
assertEquals(IptcDirectory.TAG_HEADLINE, tags[3].getTagType());
assertEquals("Headline", directory.getString(tags[3].getTagType()));
assertEquals(IptcDirectory.TAG_CAPTION_WRITER, tags[4].getTagType());
assertEquals("CaptionWriter", directory.getString(tags[4].getTagType()));
assertEquals(IptcDirectory.TAG_CAPTION, tags[5].getTagType());
assertEquals("Caption", directory.getString(tags[5].getTagType()));
assertEquals(IptcDirectory.TAG_ORIGINAL_TRANSMISSION_REFERENCE, tags[6].getTagType());
assertEquals("Transmission", directory.getString(tags[6].getTagType()));
assertEquals(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME, tags[7].getTagType());
assertEquals("Country", directory.getString(tags[7].getTagType()));
assertEquals(IptcDirectory.TAG_PROVINCE_OR_STATE, tags[8].getTagType());
assertEquals("State", directory.getString(tags[8].getTagType()));
assertEquals(IptcDirectory.TAG_CITY, tags[9].getTagType());
assertEquals("City", directory.getString(tags[9].getTagType()));
assertEquals(IptcDirectory.TAG_DATE_CREATED, tags[10].getTagType());
assertEquals("20000101", directory.getString(tags[10].getTagType()));
assertEquals(IptcDirectory.TAG_OBJECT_NAME, tags[11].getTagType());
assertEquals("ObjectName", directory.getString(tags[11].getTagType()));
assertEquals(IptcDirectory.TAG_SOURCE, tags[12].getTagType());
assertEquals("Source", directory.getString(tags[12].getTagType()));
assertEquals(IptcDirectory.TAG_CREDIT, tags[13].getTagType());
assertEquals("Credits", directory.getString(tags[13].getTagType()));
assertEquals(IptcDirectory.TAG_BY_LINE_TITLE, tags[14].getTagType());
assertEquals("BylineTitle", directory.getString(tags[14].getTagType()));
assertEquals(IptcDirectory.TAG_BY_LINE, tags[15].getTagType());
assertEquals("Byline", directory.getString(tags[15].getTagType()));
}
示例13: testIptcEncodingUtf8
import com.drew.metadata.Tag; //导入依赖的package包/类
@Test
public void testIptcEncodingUtf8() throws Exception
{
IptcDirectory directory = processBytes("Tests/Data/iptc-encoding-defined-utf8.bytes");
assertFalse(directory.getErrors().toString(), directory.hasErrors());
Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
assertEquals(4, tags.length);
assertEquals(IptcDirectory.TAG_ENVELOPE_RECORD_VERSION, tags[0].getTagType());
assertEquals(2, directory.getObject(tags[0].getTagType()));
assertEquals(IptcDirectory.TAG_CODED_CHARACTER_SET, tags[1].getTagType());
assertEquals("UTF-8", directory.getObject(tags[1].getTagType()));
assertEquals(IptcDirectory.TAG_APPLICATION_RECORD_VERSION, tags[2].getTagType());
assertEquals(2, directory.getObject(tags[2].getTagType()));
assertEquals(IptcDirectory.TAG_CAPTION, tags[3].getTagType());
assertEquals("In diesem Text sind Umlaute enthalten, nämlich öfter als üblich: ÄÖÜäöüß\r", directory.getStringValue(tags[3].getTagType()).toString());
}
示例14: testIptcEncodingUndefinedIso
import com.drew.metadata.Tag; //导入依赖的package包/类
@Test
public void testIptcEncodingUndefinedIso() throws Exception
{
IptcDirectory directory = processBytes("Tests/Data/iptc-encoding-undefined-iso.bytes");
assertFalse(directory.getErrors().toString(), directory.hasErrors());
Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
assertEquals(3, tags.length);
assertEquals(IptcDirectory.TAG_ENVELOPE_RECORD_VERSION, tags[0].getTagType());
assertEquals(2, directory.getObject(tags[0].getTagType()));
assertEquals(IptcDirectory.TAG_APPLICATION_RECORD_VERSION, tags[1].getTagType());
assertEquals(2, directory.getObject(tags[1].getTagType()));
assertEquals(IptcDirectory.TAG_CAPTION, tags[2].getTagType());
assertEquals("In diesem Text sind Umlaute enthalten, nämlich öfter als üblich: ÄÖÜäöüß\r", directory.getStringValue(tags[2].getTagType()).toString());
}
示例15: testIptcEncodingUnknown
import com.drew.metadata.Tag; //导入依赖的package包/类
@Test
public void testIptcEncodingUnknown() throws Exception
{
IptcDirectory directory = processBytes("Tests/Data/iptc-encoding-unknown.bytes");
assertFalse(directory.getErrors().toString(), directory.hasErrors());
Tag[] tags = directory.getTags().toArray(new Tag[directory.getTagCount()]);
assertEquals(3, tags.length);
assertEquals(IptcDirectory.TAG_APPLICATION_RECORD_VERSION, tags[0].getTagType());
assertEquals(2, directory.getObject(tags[0].getTagType()));
assertEquals(IptcDirectory.TAG_CAPTION, tags[1].getTagType());
assertEquals("Das Encoding dieser Metadaten ist nicht deklariert und lässt sich nur schwer erkennen.", directory.getStringValue(tags[1].getTagType()).toString());
assertEquals(IptcDirectory.TAG_KEYWORDS, tags[2].getTagType());
assertArrayEquals(new String[]{"häufig", "üblich", "Lösung", "Spaß"}, directory.getStringArray(tags[2].getTagType()));
}