本文整理匯總了Java中com.drew.metadata.Metadata.getDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java Metadata.getDirectory方法的具體用法?Java Metadata.getDirectory怎麽用?Java Metadata.getDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.drew.metadata.Metadata
的用法示例。
在下文中一共展示了Metadata.getDirectory方法的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: 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;
}
示例3: 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));
}
示例4: testDifferenceImageAndThumbnailOrientations
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@Test
public void testDifferenceImageAndThumbnailOrientations() throws Exception
{
// This metadata contains different orientations for the thumbnail and the main image.
// These values used to be merged into a single directory, causing errors.
// This unit test demonstrates correct behaviour.
Metadata metadata = processBytes("Tests/Data/repeatedOrientationTagWithDifferentValues.jpg.app1");
ExifIFD0Directory ifd0Directory = metadata.getDirectory(ExifIFD0Directory.class);
ExifThumbnailDirectory thumbnailDirectory = metadata.getDirectory(ExifThumbnailDirectory.class);
assertNotNull(ifd0Directory);
assertNotNull(thumbnailDirectory);
assertEquals(1, ifd0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION));
assertEquals(8, thumbnailDirectory.getInt(ExifThumbnailDirectory.TAG_ORIENTATION));
}
示例5: 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);
// }
}
示例6: nacti
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@Override
protected void nacti(final InputStream istm, final String name, final IImportBuilder builder, final Future<?> future) throws IOException {
if (future.isCancelled()) {
return;
}
BufferedInputStream bis;
if (istm instanceof BufferedInputStream) {
bis = (BufferedInputStream) istm;
} else {
bis = new BufferedInputStream(istm);
}
Metadata imageMetadata;
try {
imageMetadata = ImageMetadataReader.readMetadata(bis, true);
} catch (final ImageProcessingException e) {
log.error("The input stream for file " + name + "couldn't be loaded!", e);
return;
}
final GpsDirectory gpsDirectory = imageMetadata.getDirectory(GpsDirectory.class);
if (gpsDirectory == null) {
log.info("Image has no GPS metadata.");
return;
}
final GeoLocation exifLocation = gpsDirectory.getGeoLocation();
if (exifLocation != null) {
final GpxWpt gpxWpt = new GpxWpt();
gpxWpt.wgs = new Wgs(exifLocation.getLatitude(), exifLocation.getLongitude());
gpxWpt.name = Iterables.getLast(Arrays.asList(name.split(Pattern.quote(File.separator))), "");
gpxWpt.link.href = name;
gpxWpt.desc = "EXIF coordinates";
gpxWpt.type = "pic";
gpxWpt.sym = "Photo";
builder.addGpxWpt(gpxWpt);
} else {
log.info("Image {} has GPS metadata, but no lat/lon information.", name);
}
}
示例7: setHits
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
/**
* @param hits
* @param progress
*/
public void setHits(ImageSearchHits hits, JProgressBar progress) {
this.hits = hits;
icons = new ArrayList<ImageIcon>(hits.length());
if (progress != null) progress.setString("Searching finished. Loading images for result list.");
for (int i = 0; i < hits.length(); i++) {
ImageIcon icon = null;
try {
BufferedImage img = null;
String fileIdentifier = hits.doc(i).getField(DocumentBuilder.FIELD_NAME_IDENTIFIER).stringValue();
if (!fileIdentifier.startsWith("http:")) {
// check isf it is a jpg file ...
if (fileIdentifier.toLowerCase().endsWith(".jpg")) {
Metadata metadata = new ExifReader(new FileInputStream(fileIdentifier)).extract();
if (metadata.containsDirectory(ExifDirectory.class)) {
ExifDirectory exifDirectory = (ExifDirectory) metadata.getDirectory(ExifDirectory.class);
if (exifDirectory.containsThumbnail()) {
img = ImageIO.read(new ByteArrayInputStream(exifDirectory.getThumbnailData()));
}
}
}
if (img == null) {
img = ImageIO.read(new FileInputStream(fileIdentifier));
}
} else {
img = ImageIO.read(new URL(fileIdentifier));
}
icon = new ImageIcon(ImageUtils.scaleImage(img, 200));
if (progress != null) progress.setValue((i * 100) / hits.length());
} catch (Exception ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
}
icons.add(icon);
}
if (progress != null) progress.setValue(100);
fireTableDataChanged();
}
示例8: getHeight
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
private Integer getHeight(final Metadata metadata) {
Integer value = null;
ExifSubIFDDirectory directory = metadata.getDirectory(ExifSubIFDDirectory.class);
if (directory != null && directory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
value = directory.getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT);
} else {
JpegDirectory dir = metadata.getDirectory(JpegDirectory.class);
if (dir != null && dir.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
value = dir.getInteger(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
}
}
return value;
}
示例9: processBytes
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@NotNull
public static PsdHeaderDirectory processBytes(@NotNull String file) throws Exception
{
Metadata metadata = new Metadata();
RandomAccessFile randomAccessFile = new RandomAccessFile(new File(file), "r");
new PsdReader().extract(new RandomAccessFileReader(randomAccessFile), metadata);
randomAccessFile.close();
PsdHeaderDirectory directory = metadata.getDirectory(PsdHeaderDirectory.class);
assertNotNull(directory);
return directory;
}
示例10: processBytes
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@NotNull
public static IptcDirectory processBytes(@NotNull String filePath) throws IOException
{
Metadata metadata = new Metadata();
byte[] bytes = FileUtil.readBytes(filePath);
new IptcReader().extract(new SequentialByteArrayReader(bytes), metadata, bytes.length);
IptcDirectory directory = metadata.getDirectory(IptcDirectory.class);
assertNotNull(directory);
return directory;
}
示例11: processBytes
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@NotNull
public static AdobeJpegDirectory processBytes(@NotNull String filePath) throws IOException
{
Metadata metadata = new Metadata();
new AdobeJpegReader().extract(new SequentialByteArrayReader(FileUtil.readBytes(filePath)), metadata);
AdobeJpegDirectory directory = metadata.getDirectory(AdobeJpegDirectory.class);
assertNotNull(directory);
return directory;
}
示例12: extractTiff
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@Deprecated
private static void extractTiff(@NotNull final RandomAccessReader reader,
@NotNull final Metadata metadata,
@NotNull final Directory firstDirectory,
final int tiffHeaderOffset) throws IOException
{
// this should be either "MM" or "II"
String byteOrderIdentifier = reader.getString(tiffHeaderOffset, 2);
if ("MM".equals(byteOrderIdentifier)) {
reader.setMotorolaByteOrder(true);
} else if ("II".equals(byteOrderIdentifier)) {
reader.setMotorolaByteOrder(false);
} else {
firstDirectory.addError("Unclear distinction between Motorola/Intel byte ordering: " + byteOrderIdentifier);
return;
}
// Check the next two values for correctness.
final int tiffMarker = reader.getUInt16(2 + tiffHeaderOffset);
final int standardTiffMarker = 0x002A;
final int olympusRawTiffMarker = 0x4F52; // for ORF files
final int panasonicRawTiffMarker = 0x0055; // for RW2 files
if (tiffMarker != standardTiffMarker && tiffMarker != olympusRawTiffMarker && tiffMarker != panasonicRawTiffMarker) {
firstDirectory.addError("Unexpected TIFF marker after byte order identifier: 0x" + Integer.toHexString(tiffMarker));
return;
}
int firstIfdOffset = reader.getInt32(4 + tiffHeaderOffset) + tiffHeaderOffset;
// David Ekholm sent a digital camera image that has this problem
// TODO getLength should be avoided as it causes RandomAccessStreamReader to read to the end of the stream
if (firstIfdOffset >= reader.getLength() - 1) {
firstDirectory.addError("First Exif directory offset is beyond end of Exif data segment");
// First directory normally starts 14 bytes in -- try it here and catch another error in the worst case
firstIfdOffset = 14;
}
Set<Integer> processedIfdOffsets = new HashSet<Integer>();
processIFD(firstDirectory, processedIfdOffsets, firstIfdOffset, tiffHeaderOffset, metadata, reader);
// after the extraction process, if we have the correct tags, we may be able to store thumbnail information
ExifThumbnailDirectory thumbnailDirectory = metadata.getDirectory(ExifThumbnailDirectory.class);
if (thumbnailDirectory != null && thumbnailDirectory.containsTag(ExifThumbnailDirectory.TAG_THUMBNAIL_COMPRESSION)) {
Integer offset = thumbnailDirectory.getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET);
Integer length = thumbnailDirectory.getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH);
if (offset != null && length != null) {
try {
byte[] thumbnailData = reader.getBytes(tiffHeaderOffset + offset, length);
thumbnailDirectory.setThumbnailData(thumbnailData);
} catch (IOException ex) {
firstDirectory.addError("Invalid thumbnail data specification: " + ex.getMessage());
}
}
}
}
示例13: 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";
}
}
示例14: nactiKdyzUmis
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@Override
protected void nactiKdyzUmis(InputStream istm, String jmeno, IImportBuilder builder, Future<?> future)
throws IOException {
if (!VALID_FILENAME_REGEX.matcher(jmeno).matches()) {
return;
}
BufferedInputStream bis;
if (istm instanceof BufferedInputStream) {
bis = (BufferedInputStream) istm;
} else {
bis = new BufferedInputStream(istm);
}
Metadata imageMetadata;
try {
imageMetadata = ImageMetadataReader.readMetadata(bis, true);
} catch (ImageProcessingException e) {
log.error("The input stream with name " + jmeno + " couldn't be loaded!", e);
return;
}
GpsDirectory gpsDirectory = imageMetadata.getDirectory(GpsDirectory.class);
if (gpsDirectory == null) {
log.info("Image {} has no GPS metadata.", jmeno);
return;
}
GeoLocation exifLocation = gpsDirectory.getGeoLocation();
if (exifLocation != null) {
GpxWpt gpxWpt = new GpxWpt();
gpxWpt.wgs = new Wgs(exifLocation.getLatitude(), exifLocation.getLongitude());
gpxWpt.name = Iterables.getLast(Arrays.asList(jmeno.split(Pattern.quote(File.separator))), "");
gpxWpt.link.href = jmeno;
gpxWpt.desc = "EXIF coordinates";
gpxWpt.type = "pic";
gpxWpt.sym = "Photo";
builder.addGpxWpt(gpxWpt);
} else {
log.info("Image {} has GPS metadata, but no lat/lon information.", jmeno);
}
}
示例15: processBytes
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@NotNull
public static BmpHeaderDirectory processBytes(@NotNull String file) throws Exception
{
Metadata metadata = new Metadata();
InputStream stream = new FileInputStream(file);
new BmpReader().extract(new StreamReader(stream), metadata);
stream.close();
BmpHeaderDirectory directory = metadata.getDirectory(BmpHeaderDirectory.class);
assertNotNull(directory);
return directory;
}