本文整理汇总了Java中com.drew.metadata.Metadata.getDirectories方法的典型用法代码示例。如果您正苦于以下问题:Java Metadata.getDirectories方法的具体用法?Java Metadata.getDirectories怎么用?Java Metadata.getDirectories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.drew.metadata.Metadata
的用法示例。
在下文中一共展示了Metadata.getDirectories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printImageTags
import com.drew.metadata.Metadata; //导入方法依赖的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.Metadata; //导入方法依赖的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.Metadata; //导入方法依赖的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: onExtractionSuccess
import com.drew.metadata.Metadata; //导入方法依赖的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();
}
}
}
示例5: onExtracted
import com.drew.metadata.Metadata; //导入方法依赖的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();
}
}
}
示例6: parseMetadata
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
@Override
protected void parseMetadata(Metadata metadata) {
if (metadata == null) {
return;
}
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof WebpDirectory) {
parsedInfo.format = ImageFormat.WEBP;
if (
((WebpDirectory) directory).containsTag(WebpDirectory.TAG_IMAGE_WIDTH) &&
((WebpDirectory) directory).containsTag(WebpDirectory.TAG_IMAGE_HEIGHT)
) {
parsedInfo.width = ((WebpDirectory) directory).getInteger(WebpDirectory.TAG_IMAGE_WIDTH);
parsedInfo.height = ((WebpDirectory) directory).getInteger(WebpDirectory.TAG_IMAGE_HEIGHT);
}
}
}
}
示例7: parseExifOrientation
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
/**
* Tries to parse {@link ExifOrientation} from the given metadata. If it
* fails, {@code defaultOrientation} is returned.
*
* @param metadata the {@link Metadata} to parse.
* @param defaultOrientation the default to return if parsing fails.
* @return The parsed {@link ExifOrientation} or {@code defaultOrientation}.
*/
public static ExifOrientation parseExifOrientation(Metadata metadata, ExifOrientation defaultOrientation) {
if (metadata == null) {
return defaultOrientation;
}
try {
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof ExifIFD0Directory) {
if (((ExifIFD0Directory) directory).containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
return ExifOrientation.typeOf(((ExifIFD0Directory) directory).getInt(ExifIFD0Directory.TAG_ORIENTATION));
}
}
}
} catch (MetadataException e) {
return defaultOrientation;
}
return defaultOrientation;
}
示例8: parseMetadata
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
@Override
protected void parseMetadata(Metadata metadata) {
if (metadata == null) {
return;
}
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof IcoDirectory) {
parsedInfo.format = ImageFormat.ICO;
if (
((IcoDirectory) directory).containsTag(IcoDirectory.TAG_IMAGE_WIDTH) &&
((IcoDirectory) directory).containsTag(IcoDirectory.TAG_IMAGE_HEIGHT)
) {
parsedInfo.width = ((IcoDirectory) directory).getInteger(IcoDirectory.TAG_IMAGE_WIDTH);
parsedInfo.height = ((IcoDirectory) directory).getInteger(IcoDirectory.TAG_IMAGE_HEIGHT);
}
}
}
}
示例9: parseMetadata
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
@Override
protected void parseMetadata(Metadata metadata) {
if (metadata == null) {
return;
}
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof PcxDirectory) {
parsedInfo.format = ImageFormat.PCX;
if (
((PcxDirectory) directory).containsTag(PcxDirectory.TAG_XMIN) &&
((PcxDirectory) directory).containsTag(PcxDirectory.TAG_XMAX) &&
((PcxDirectory) directory).containsTag(PcxDirectory.TAG_YMIN) &&
((PcxDirectory) directory).containsTag(PcxDirectory.TAG_YMAX)
) {
Integer min = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_XMIN);
Integer max = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_XMAX);
if (min != null && max != null) {
parsedInfo.width = max.intValue() - min.intValue() + 1;
}
min = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_YMIN);
max = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_YMAX);
if (min != null && max != null) {
parsedInfo.height = max.intValue() - min.intValue() + 1;
}
}
}
}
}
示例10: writeHierarchyLevel
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
private static void writeHierarchyLevel(@NotNull Metadata metadata, @NotNull PrintWriter writer, @Nullable Directory parent, int level)
{
final int indent = 4;
for (Directory child : metadata.getDirectories()) {
if (parent == null) {
if (child.getParent() != null)
continue;
} else if (!parent.equals(child.getParent())) {
continue;
}
for (int i = 0; i < level*indent; i++) {
writer.write(' ');
}
writer.write("- ");
writer.write(child.getName());
writer.write(NEW_LINE);
writeHierarchyLevel(metadata, writer, child, level + 1);
}
}
示例11: Row
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
Row(@NotNull File file, @NotNull Metadata metadata)
{
this.file = file;
this.metadata = metadata;
ExifIFD0Directory ifd0Dir = metadata.getDirectory(ExifIFD0Directory.class);
ExifSubIFDDirectory subIfdDir = metadata.getDirectory(ExifSubIFDDirectory.class);
ExifThumbnailDirectory thumbDir = metadata.getDirectory(ExifThumbnailDirectory.class);
if (ifd0Dir != null) {
manufacturer = ifd0Dir.getDescription(ExifIFD0Directory.TAG_MAKE);
model = ifd0Dir.getDescription(ExifIFD0Directory.TAG_MODEL);
}
boolean hasMakernoteData = false;
if (subIfdDir != null) {
exifVersion = subIfdDir.getDescription(ExifSubIFDDirectory.TAG_EXIF_VERSION);
hasMakernoteData = subIfdDir.containsTag(ExifSubIFDDirectory.TAG_MAKERNOTE);
}
if (thumbDir != null) {
Integer width = thumbDir.getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_WIDTH);
Integer height = thumbDir.getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT);
thumbnail = width != null && height != null
? String.format("Yes (%s x %s)", width, height)
: "Yes";
}
for (Directory directory : metadata.getDirectories()) {
if (directory.getClass().getName().contains("Makernote")) {
makernote = directory.getName().replace("Makernote", "").trim();
}
}
if (makernote == null) {
makernote = hasMakernoteData ? "(Unknown)" : "N/A";
}
}
示例12: setToArray
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
public void setToArray(Metadata metadata){
for (Directory directory : metadata.getDirectories()) {
directory.getTags().forEach((tag) -> {
if (!directory.hasErrors()) {
out.add(tag.getTagName()+" "+tag.getDescription());
System.out.println(tag.toString());
}
});
}
}
示例13: parseMetadata
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
@Override
protected void parseMetadata(Metadata metadata) throws ParseException {
if (metadata == null) {
return;
}
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof GifHeaderDirectory) {
parsedInfo.format = ImageFormat.GIF;
parsedInfo.numComponents = 3;
if (
((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_IMAGE_WIDTH) &&
((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_IMAGE_HEIGHT)
) {
parsedInfo.width = ((GifHeaderDirectory) directory).getInteger(GifHeaderDirectory.TAG_IMAGE_WIDTH);
parsedInfo.height = ((GifHeaderDirectory) directory).getInteger(GifHeaderDirectory.TAG_IMAGE_HEIGHT);
}
if (((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_BITS_PER_PIXEL)) {
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
Integer i = ((GifHeaderDirectory) directory).getInteger(GifHeaderDirectory.TAG_BITS_PER_PIXEL);
if (i != null) {
parsedInfo.bitDepth = i.intValue();
}
}
if (((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_GIF_FORMAT_VERSION)) {
String s = ((GifHeaderDirectory) directory).getString(GifHeaderDirectory.TAG_GIF_FORMAT_VERSION, "US-ASCII");
if (s != null) {
((GIFParseInfo) parsedInfo).formatVersion = s;
}
}
} else if (directory instanceof GifControlDirectory) {
boolean hasTransparency = ((GifControlDirectory) directory).isTransparent();
((GIFParseInfo) parsedInfo).hasTransparency = hasTransparency;
if (hasTransparency) {
if (parsedInfo.numComponents == null) {
throw new ParseException(
"Invalid GIF image - Graphic Control Extension block encountered before the Header block"
);
}
parsedInfo.numComponents = 4;
}
}
}
}
示例14: printAllTags
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
/**
* Prints Tag.getDescription() of all Tags in Metadata
*
* @param metadata Metadata read from image file
*/
public static void printAllTags(Metadata metadata) {
if(metadata == null) {
System.out.println("Metadata was null. Nothing to print.");
}
for(Directory dir : metadata.getDirectories()) {
System.out.println("Directory: " + dir.getName());
for(Tag tag : dir.getTags()) {
System.out.println("\tTag: " + tag.getTagName() + ", Value: " + tag.getDescription());
}
}
}
示例15: readMetadata
import com.drew.metadata.Metadata; //导入方法依赖的package包/类
/**
* Read metadata from picture
*
* @param source
* @return
* @throws ImageProcessingException
* @throws IOException
*/
public static Set<gal.udc.fic.muei.tfm.dap.flipper.domain.Metadata> readMetadata(byte[] source) throws ImageProcessingException, IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(source);
Metadata metadata = ImageMetadataReader.readMetadata(bis);
Set<gal.udc.fic.muei.tfm.dap.flipper.domain.Metadata> result = new HashSet<gal.udc.fic.muei.tfm.dap.flipper.domain.Metadata>();
for (Directory directory : metadata.getDirectories()) {
result.addAll(directory.getTags().stream().map(tag -> new gal.udc.fic.muei.tfm.dap.flipper.domain.Metadata(
directory.getName(), tag.getTagType(), tag.getTagName(), tag.getDescription())).collect(Collectors.toList()));
}
return result;
}