本文整理匯總了Java中com.drew.metadata.Directory.getTags方法的典型用法代碼示例。如果您正苦於以下問題:Java Directory.getTags方法的具體用法?Java Directory.getTags怎麽用?Java Directory.getTags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.drew.metadata.Directory
的用法示例。
在下文中一共展示了Directory.getTags方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: printImageTags
import com.drew.metadata.Directory; //導入方法依賴的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.Directory; //導入方法依賴的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.Directory; //導入方法依賴的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.Directory; //導入方法依賴的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.Directory; //導入方法依賴的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.Directory; //導入方法依賴的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.Directory; //導入方法依賴的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.Directory; //導入方法依賴的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: extractMetadata
import com.drew.metadata.Directory; //導入方法依賴的package包/類
static ExtractedMetadata extractMetadata(Metadata metadata, String uri, Logger logger) throws Exception {
ExtractedMetadata propsVals = new ExtractedMetadata();
for (Directory directory : metadata.getDirectories()) {
if (null != logger) logger.info (" found metadata group: '" + directory.getName() + "'");
for (Tag tag : directory.getTags()) {
if (null != logger) logger.info(" found metadata tag: '" + tag.getTagName() + "' -> '" + tag.getDescription() + "' [" + tag.getTagType() + "]");
String predicate = EXIF_NS + tag.getTagName().toLowerCase().replaceAll("[ /()&<>]","_");
propsVals.addPropertyValue(predicate, tag.getDescription());
}
}
return propsVals;
}
示例10: convert
import com.drew.metadata.Directory; //導入方法依賴的package包/類
@PUT
@Path("pic")
@Consumes("image/*")
@Produces("text/plain")
public String convert(File img) throws /*FileNotFoundException,*/ IOException, ImageProcessingException {
Metadata meta = ImageMetadataReader.readMetadata(img);
StringBuilder sb = new StringBuilder();
for (Directory directory : meta.getDirectories()) {
sb.append(directory.getName()).append(":\n");
for (Tag tag : directory.getTags()) {
sb.append(tag).append('\n');
}
}
return sb.toString();
}
示例11: writeDataToFile
import com.drew.metadata.Directory; //導入方法依賴的package包/類
public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
fos.close();
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
// copy original exif data to the output exif...
// unfortunately, this Android ExifInterface class doesn't understand all the tags so we lose some
for (Directory directory : originalImageMetaData().getDirectories()) {
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
Object object = directory.getObject(tagType);
exif.setAttribute(tag.getTagName(), object.toString());
}
}
writeLocationExifData(options, exif);
if(hasBeenReoriented)
rewriteOrientation(exif);
exif.saveAttributes();
} catch (ImageProcessingException | IOException e) {
Log.e(TAG, "failed to save exif data", e);
}
}
示例12: writeDataToFile
import com.drew.metadata.Directory; //導入方法依賴的package包/類
public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
fos.close();
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
// copy original exif data to the output exif...
// unfortunately, this Android ExifInterface class doesn't understand all the tags so we lose some
for (Directory directory : originalImageMetaData().getDirectories()) {
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
Object object = directory.getObject(tagType);
exif.setAttribute(tag.getTagName(), object.toString());
}
}
writeLocationExifData(options, exif);
if(hasBeenReoriented)
rewriteOrientation(exif);
exif.saveAttributes();
} catch (ImageProcessingException | IOException e) {
Log.e(TAG, "failed to save exif data", e);
}
}
示例13: printAllTags
import com.drew.metadata.Directory; //導入方法依賴的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());
}
}
}
示例14: print
import com.drew.metadata.Directory; //導入方法依賴的package包/類
private static void print(Metadata metadata)
{
System.out.println("-------------------------------------");
// Iterate over the data and print to System.out
//
// A Metadata object contains multiple Directory objects
//
for (Directory directory : metadata.getDirectories()) {
//
// Each Directory stores values in Tag objects
//
for (Tag tag : directory.getTags()) {
System.out.println(tag);
}
//
// Each Directory may also contain error messages
//
if (directory.hasErrors()) {
for (String error : directory.getErrors()) {
System.err.println("ERROR: " + error);
}
}
}
}
示例15: getImageTiffMetadata
import com.drew.metadata.Directory; //導入方法依賴的package包/類
public static void getImageTiffMetadata(File tifffile) throws ImageProcessingException, IOException {
// works for tiff but has many unknown tags
com.drew.metadata.Metadata drewmetadata = null;
drewmetadata = ImageMetadataReader.readMetadata(tifffile);
if (drewmetadata != null) {
for (Directory directory : drewmetadata.getDirectories()) {
System.out.println("directory: " + directory);
for (Tag tag : directory.getTags()) {
System.out.println(" tag: " + tag);
}
}
}
}