本文整理汇总了Java中com.drew.metadata.exif.ExifIFD0Directory类的典型用法代码示例。如果您正苦于以下问题:Java ExifIFD0Directory类的具体用法?Java ExifIFD0Directory怎么用?Java ExifIFD0Directory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExifIFD0Directory类属于com.drew.metadata.exif包,在下文中一共展示了ExifIFD0Directory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getShootTime
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的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: getOrientation
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的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 "";
}
示例3: fixOrientation
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的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);
}
}
示例4: parseExifOrientation
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的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;
}
示例5: main
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的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));
}
示例6: handleExifIFD0Directory
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
private void handleExifIFD0Directory(MetaData metaData, Directory directory) throws MetadataException{
metaData.put(Image.MetaName.Make, getStringValue(directory, ExifIFD0Directory.TAG_MAKE));
metaData.put(Image.MetaName.Model, getStringValue(directory, ExifIFD0Directory.TAG_MODEL));
metaData.put(Image.MetaName.Software, getStringValue(directory, ExifIFD0Directory.TAG_SOFTWARE));
// Date/Time Original overrides value from ExifDirectory.TAG_DATETIME
// Unless we have GPS time we don't know the time zone so date must be set
// as ISO 8601 datetime without timezone suffix (no Z or +/-)
if (directory.containsTag(ExifIFD0Directory.TAG_DATETIME)) {
metaData.put(Image.MetaName.DateTimeOriginal, getDateValue(directory, ExifIFD0Directory.TAG_DATETIME));
}
if (directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)){
Integer val = getIntValue(directory, ExifIFD0Directory.TAG_ORIENTATION);
metaData.put(Image.MetaName.Orientation, translateOrientation(val));
}
}
示例7: getOrientation
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
private static int getOrientation(byte[] data) {
InputStream is = null;
try {
is = new ByteArrayInputStream(data);
Metadata metadata = ImageMetadataReader.readMetadata(is);
Collection<ExifIFD0Directory> directories = metadata.getDirectoriesOfType(ExifIFD0Directory.class);
for(ExifIFD0Directory directory : directories) {
if(directory.containsTag(ExifDirectoryBase.TAG_ORIENTATION)) {
return directory.getInt(ExifDirectoryBase.TAG_ORIENTATION);
}
}
return ExifInterface.ORIENTATION_NORMAL;
}
catch (Exception e) {
return ExifInterface.ORIENTATION_NORMAL;
}
finally {
if(is != null) try { is.close(); } catch(Exception ignore) {}
}
}
示例8: supports
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
public boolean supports(Class<? extends Directory> directoryType) {
return directoryType == ExifIFD0Directory.class ||
directoryType == ExifSubIFDDirectory.class;
}
示例9: getOrientation
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
private static int getOrientation(BufferedInputStream bis) throws IOException {
try {
Metadata metadata = ImageMetadataReader.readMetadata(bis);
Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
if (directory != null) {
return directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
}
return 1;
} catch (MetadataException | ImageProcessingException me) {
return 1;
}
}
示例10: testOrderOfDifferentTypes
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
@Test
public void testOrderOfDifferentTypes()
{
Metadata metadata = new Metadata();
Directory directory1 = new ExifSubIFDDirectory();
Directory directory2 = new ExifThumbnailDirectory();
Directory directory3 = new ExifIFD0Directory();
metadata.addDirectory(directory1);
metadata.addDirectory(directory2);
metadata.addDirectory(directory3);
List<Directory> directories = new ArrayList<Directory>();
for (Directory directory : metadata.getDirectories()) {
directories.add(directory);
}
assertEquals(3, directories.size());
assertSame(directory1, directories.toArray()[0]);
assertSame(directory2, directories.toArray()[1]);
assertSame(directory3, directories.toArray()[2]);
}
示例11: Row
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的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: getImageDate
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
Date getImageDate(File file) throws Exception {
try {
Metadata metadata = ImageMetadataReader.readMetadata(file);
ExifSubIFDDirectory exifSubIFDDirectory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
int tagDatetimeOriginal = ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL;
ExifIFD0Directory exifIFD0Directory;
exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
int tagDatetime = ExifIFD0Directory.TAG_DATETIME;
if (exifSubIFDDirectory != null && exifSubIFDDirectory.getDate(tagDatetimeOriginal,
TimeZone.getDefault()) !=
null) {
return exifSubIFDDirectory.getDate(tagDatetimeOriginal, TimeZone.getDefault());
}
if (exifIFD0Directory != null && exifIFD0Directory.getDate(tagDatetime,
TimeZone.getDefault()) != null) {
return exifIFD0Directory.getDate(tagDatetime, TimeZone.getDefault());
}
throw new CouldNotParseDateException();
}
catch (ImageProcessingException | IOException e) {
throw new CouldNotParseDateException("File: " + file.getName());
}
}
示例13: updateImageInfo
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
public void updateImageInfo(Path filePath) throws Exception {
this.mimeType = tika.detect(filePath.toFile());;
// Read image metadata using metadata-extractor - only for tiff
Metadata metadata = ImageMetadataReader.readMetadata(filePath.toFile());
ExifIFD0Directory directory = metadata.getDirectory(ExifIFD0Directory.class);
if (directory == null) {
throw new Exception("Missing ExifIFD0Directory: " + filePath.toString());
}
// Compression (259)
this.compression = getTagValue(directory, 259);
// Samples per pixel (277)
this.samplesPerPixel = getTagValue(directory, 277);
// Bits per sample (258)
this.bitsPerSample = getTagValue(directory, 258);
// Photometric (262)
this.photometric = getTagValue(directory, 262);
}
示例14: getJpegData
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
protected void getJpegData(byte[] toMatch, int i, List<Integer> offsets, int resultIndex) {
try {
Metadata reader = JpegMetadataReader
.readMetadata(new ByteArrayInputStream(Arrays.copyOfRange(toMatch, i - offsets.get(resultIndex), toMatch.length)));
ExifIFD0Directory info = reader.getFirstDirectoryOfType(ExifIFD0Directory.class);
String cameraMake = null;
String cameraModel = null;
if (info != null) {
cameraMake = info.getString(ExifDirectoryBase.TAG_MAKE);
cameraModel = info.getString(ExifDirectoryBase.TAG_MODEL);
}
for (Directory dir : reader.getDirectoriesOfType(GpsDirectory.class)) {
GpsDescriptor descriptor = new GpsDescriptor((GpsDirectory) dir);
Map<String, String> gpsInfoDict = new LinkedHashMap<>();
gpsInfoDict.put("Camera Make: ", cameraMake);
gpsInfoDict.put("Camera Model: ", cameraModel);
gpsInfoDict.put("Latitude: ", tagOrEmpty(descriptor.getGpsLatitudeDescription()));
gpsInfoDict.put("Longitude: ", tagOrEmpty(descriptor.getGpsLongitudeDescription()));
gpsInfoDict.put("Altitude: ", descriptor.getGpsAltitudeDescription());
gpsInfoDict.put("Altitude Reference: ", descriptor.getGpsAltitudeRefDescription());
gpsInfoDict.put("Timestamp: ", descriptor.getGpsTimeStampDescription());
if (notEmptyGPS(descriptor.getGpsLatitudeDescription(), descriptor.getGpsLongitudeDescription())) {
logGPS(gpsInfoDict);
wasGPSFound = true;
}
}
}
catch (IOException | ImageProcessingException e) {
e.printStackTrace();
}
}
示例15: testToString
import com.drew.metadata.exif.ExifIFD0Directory; //导入依赖的package包/类
@Test
public void testToString()
{
Directory directory = new ExifIFD0Directory();
assertEquals("Exif IFD0 Directory (0 tags)", directory.toString());
directory.setString(1, "Tag 1");
assertEquals("Exif IFD0 Directory (1 tag)", directory.toString());
directory.setString(2, "Tag 2");
assertEquals("Exif IFD0 Directory (2 tags)", directory.toString());
}