本文整理匯總了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;
}
}
示例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);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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 "";
}
}
示例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);
}
}
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
}
}
}
}
示例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;
}
示例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));
}
示例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);
// }
}