当前位置: 首页>>代码示例>>Java>>正文


Java Metadata.getDirectory方法代码示例

本文整理汇总了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;
	}  
         
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:25,代码来源:ExifUtils.java

示例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;
}
 
开发者ID:caomu,项目名称:img,代码行数:28,代码来源:Distribute.java

示例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));
  }
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:17,代码来源:ExifUtils.java

示例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));
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:17,代码来源:ExifReaderTest.java

示例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);
//        }
    }
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:22,代码来源:IccReaderTest.java

示例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);
	}
}
 
开发者ID:marvertin,项目名称:geokuk,代码行数:38,代码来源:NacitacImageMetadata.java

示例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();
}
 
开发者ID:fish2000,项目名称:lire,代码行数:41,代码来源:SearchResultsTableModel.java

示例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;
}
 
开发者ID:rizzow,项目名称:atombox-standalone,代码行数:14,代码来源:JpegImporter.java

示例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;
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:13,代码来源:PsdReaderTest.java

示例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;
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:11,代码来源:IptcReaderTest.java

示例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;
}
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:11,代码来源:AdobeJpegReaderTest.java

示例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());
            }
        }
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:59,代码来源:ExifReader.java

示例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";
    }
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:34,代码来源:ProcessAllImagesInFolderUtility.java

示例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);
  }
}
 
开发者ID:Danstahr,项目名称:Geokuk,代码行数:39,代码来源:NacitacImageMetadata.java

示例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;
}
 
开发者ID:byronb92,项目名称:ImageEXIFExtraction,代码行数:13,代码来源:BmpReaderTest.java


注:本文中的com.drew.metadata.Metadata.getDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。