當前位置: 首頁>>代碼示例>>Java>>正文


Java Metadata類代碼示例

本文整理匯總了Java中com.drew.metadata.Metadata的典型用法代碼示例。如果您正苦於以下問題:Java Metadata類的具體用法?Java Metadata怎麽用?Java Metadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Metadata類屬於com.drew.metadata包,在下文中一共展示了Metadata類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getShootTime

import com.drew.metadata.Metadata; //導入依賴的package包/類
/**
 * 獲取拍攝時間
 * @param path 照片路徑
 * @return   秒數
 */
public static int getShootTime(String path){
	File jpegFile = new File(path);  
       Metadata metadata;
	try {
		metadata = JpegMetadataReader.readMetadata(jpegFile);
		Directory exif = metadata.getDirectory(ExifIFD0Directory.class); 
        String model = exif.getString(ExifIFD0Directory.TAG_DATETIME);
        
        //Date/Time ==> 2015:09:17 15:24:43
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        Date d = sdf1.parse(model);
        return (int) (d.getTime() / 1000);
        
	} catch (Exception e) {
		e.printStackTrace();
		return 0;
	}  
         
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:25,代碼來源:ExifUtils.java

示例2: 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);
}
 
開發者ID:wsldl123292,項目名稱:testeverything,代碼行數:28,代碼來源:ImgClassification.java

示例3: 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();
    }
}
 
開發者ID:varunon9,項目名稱:Image-Stegano,代碼行數:20,代碼來源:ImageStegano.java

示例4: 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;
}
 
開發者ID:probestar,項目名稱:PhotoCollector,代碼行數:18,代碼來源:PhotoCollectorUtils.java

示例5: readMetdataFor

import com.drew.metadata.Metadata; //導入依賴的package包/類
public Metadata readMetdataFor(File f) throws JpegProcessingException {
  Metadata m = null;
  try {
      String mime = Files.probeContentType(f.toPath());
      System.out.println(mime);
      switch(mime){
          case "image/jpeg":
              m = JpegMetadataReader.readMetadata(f,readers);
              break;
          case "image/png":
              m = PngMetadataReader.readMetadata(f);
              break;
          case "image/gif":
              m = GifMetadataReader.readMetadata(f);
              break;
          case "image/bmp":
              m = BmpMetadataReader.readMetadata(f);
              break;
      }
  } catch (IOException | PngProcessingException ex) {
      Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  }
  return m;
}
 
開發者ID:Obsidiam,項目名稱:joanne,代碼行數:25,代碼來源:ImageManager.java

示例6: fixOrientation

import com.drew.metadata.Metadata; //導入依賴的package包/類
public void fixOrientation() throws ImageMutationFailedException {
    try {
        Metadata metadata = originalImageMetaData();

        ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
        if (exifIFD0Directory == null) {
            return;
        } else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
            int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
            if(exifOrientation != 1) {
                rotate(exifOrientation);
                exifIFD0Directory.setInt(ExifIFD0Directory.TAG_ORIENTATION, 1);
            }
        }
    } catch (ImageProcessingException | IOException | MetadataException e) {
        throw new ImageMutationFailedException("failed to fix orientation", e);
    }
}
 
開發者ID:jonathan68,項目名稱:react-native-camera,代碼行數:19,代碼來源:MutableImage.java

示例7: getDateFromImgEXIF

import com.drew.metadata.Metadata; //導入依賴的package包/類
/**
 * @param f
 * @return
 * @throws IOException
 */
private String getDateFromImgEXIF(final File file) throws IOException {
	String date = null;
	if (file.isFile()) {
		try {
			final Metadata metadata = ImageMetadataReader
					.readMetadata(file);
			// obtain the Exif directory
			final Directory directory = metadata
					.getDirectory(ExifSubIFDDirectory.class);
			if (null != directory) {
				final Date tagDate = directory
						.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
				if (null != tagDate) {
					date = this.sdf.format(tagDate);
				}
			}
		} catch (final ImageProcessingException e) {
			// e.printStackTrace();
		}
	}
	return date;
}
 
開發者ID:caomu,項目名稱:img,代碼行數:28,代碼來源:Distribute.java

示例8: getExifDate

import com.drew.metadata.Metadata; //導入依賴的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

示例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 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);
			}
		}
	}
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:20,代碼來源:WebPInfo.java

示例10: 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;
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:26,代碼來源:ImagesUtil.java

示例11: 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);
			}
		}
	}
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:20,代碼來源:ICOInfo.java

示例12: 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;
				}
			}
		}
	}
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:30,代碼來源:PCXInfo.java

示例13: JPEGInfo

import com.drew.metadata.Metadata; //導入依賴的package包/類
/**
 * Use
 * {@link ImageInfo#create(int, int, Metadata, ImageFormat, long, boolean, boolean)}
 * to instantiate.
 */
protected JPEGInfo(
	int width,
	int height,
	Metadata metadata,
	ImageFormat format,
	long size,
	boolean applyExifOrientation,
	boolean throwOnParseFailure
) throws ParseException {
	super(width, height, metadata, format, size, applyExifOrientation, throwOnParseFailure);

	jfifVersion = ((JPEGParseInfo) parsedInfo).jfifVersion;
	compressionType = ((JPEGParseInfo) parsedInfo).compressionType;
	components = ((JPEGParseInfo) parsedInfo).components;
	isTypicalHuffman = ((JPEGParseInfo) parsedInfo).isTypicalHuffman;
	chromaSubsampling = ((JPEGParseInfo) parsedInfo).chromaSubsampling;
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:23,代碼來源:JPEGInfo.java

示例14: main

import com.drew.metadata.Metadata; //導入依賴的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));
  }
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:17,代碼來源:ExifUtils.java

示例15: testExtract

import com.drew.metadata.Metadata; //導入依賴的package包/類
@Test
    public void testExtract() throws Exception
    {
        byte[] app2Bytes = FileUtil.readBytes("Tests/Data/iccDataInvalid1.jpg.app2");

        // ICC data starts after a 14-byte preamble
        byte[] icc = TestHelper.skipBytes(app2Bytes, 14);

        Metadata metadata = new Metadata();
        new IccReader().extract(new ByteArrayReader(icc), metadata);

        IccDirectory directory = metadata.getDirectory(IccDirectory.class);

        assertNotNull(directory);

        // TODO validate expected values

//        for (Tag tag : directory.getTags()) {
//            System.out.println(tag);
//        }
    }
 
開發者ID:ydanila,項目名稱:j-metadata-extractor,代碼行數:22,代碼來源:IccReaderTest.java


注:本文中的com.drew.metadata.Metadata類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。