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


Java ImageMetadataReader.readMetadata方法代碼示例

本文整理匯總了Java中com.drew.imaging.ImageMetadataReader.readMetadata方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageMetadataReader.readMetadata方法的具體用法?Java ImageMetadataReader.readMetadata怎麽用?Java ImageMetadataReader.readMetadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.drew.imaging.ImageMetadataReader的用法示例。


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

示例1: printImageTags

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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

示例2: metaDataMenuItemActionPerformed

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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

示例3: readExif

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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

示例4: getOrientation

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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 "";
}
 
開發者ID:web-education,項目名稱:mod-image-resizer,代碼行數:17,代碼來源:ImageResizer.java

示例5: getDateFromImgEXIF

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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

示例6: getExifDate

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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

示例7: MetadataProcessor

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的package包/類
public MetadataProcessor(File imageFile) {
    this.imageFile = imageFile;
    try {
        data = ImageMetadataReader.readMetadata(imageFile);
    } catch (Exception ex) {
        Logger.getLogger(MetadataProcessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    for (Directory directory : data.getDirectories()) {
        extracted_data += String.format("----------------------------------------------%15s---------------------------------\n", directory.getName());
        for (Tag tag : directory.getTags()) {
            extracted_data += tag + "\n";
        }
        if (directory.hasErrors()) {
            for (String error : directory.getErrors()) {
                System.err.println("ERROR: " + error);
            }
        }
    }
}
 
開發者ID:afsalashyana,項目名稱:FakeImageDetection,代碼行數:21,代碼來源:MetadataProcessor.java

示例8: nacti

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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

示例9: getOrientation

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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) {}
  }
}
 
開發者ID:staticbloc,項目名稱:media,代碼行數:22,代碼來源:PhotoCaptureRequest.java

示例10: getOrientation

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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;
	}
}
 
開發者ID:oglimmer,項目名稱:lunchy,代碼行數:13,代碼來源:ImageScaler.java

示例11: nactiKdyzUmis

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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

示例12: testWindowsXpFields

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的package包/類
@Test
    public void testWindowsXpFields() throws Exception
    {
        String fileName = "Tests/com/drew/metadata/exif/windowsXpFields.jpg";
        Metadata metadata = ImageMetadataReader.readMetadata(new File(fileName));
//        Metadata metadata = new Metadata();
//        final byte[] data = new JpegSegmentReader(new File(fileName)).readSegment(JpegSegmentReader.SEGMENT_APP1);
//        Assert.assertNotNull(data);
//        new ExifReader().extract(data, metadata);
        ExifIFD0Directory directory = metadata.getDirectory(ExifIFD0Directory.class);
        Assert.assertNotNull(directory);

        Assert.assertEquals("Testing artist\0", directory.getString(ExifIFD0Directory.TAG_WIN_AUTHOR, "UTF-16LE"));
        Assert.assertEquals("Testing comments\0", directory.getString(ExifIFD0Directory.TAG_WIN_COMMENT, "UTF-16LE"));
        Assert.assertEquals("Testing keywords\0", directory.getString(ExifIFD0Directory.TAG_WIN_KEYWORDS, "UTF-16LE"));
        Assert.assertEquals("Testing subject\0", directory.getString(ExifIFD0Directory.TAG_WIN_SUBJECT, "UTF-16LE"));
        Assert.assertEquals("Testing title\0", directory.getString(ExifIFD0Directory.TAG_WIN_TITLE, "UTF-16LE"));

        ExifIFD0Descriptor descriptor = new ExifIFD0Descriptor(directory);
        Assert.assertEquals("Testing artist", descriptor.getDescription(ExifIFD0Directory.TAG_WIN_AUTHOR));
        Assert.assertEquals("Testing comments", descriptor.getDescription(ExifIFD0Directory.TAG_WIN_COMMENT));
        Assert.assertEquals("Testing keywords", descriptor.getDescription(ExifIFD0Directory.TAG_WIN_KEYWORDS));
        Assert.assertEquals("Testing subject", descriptor.getDescription(ExifIFD0Directory.TAG_WIN_SUBJECT));
        Assert.assertEquals("Testing title", descriptor.getDescription(ExifIFD0Directory.TAG_WIN_TITLE));
    }
 
開發者ID:mxbossard,項目名稱:metadata-extractor-osgi,代碼行數:26,代碼來源:ExifIFD0DescriptorTest.java

示例13: buildMedia

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的package包/類
protected final Media buildMedia(final MediaUploadBatch context) throws MediaReaderException, IOException {
    final String fileName = getFile().getAbsolutePath();
    try {
        final Metadata rawMetadata = ImageMetadataReader.readMetadata(getFile());
        final byte[] thumbnail;
        if (rawMetadata.containsDirectoryOfType(ExifThumbnailDirectory.class)) {
            final ExifThumbnailDirectory thumbnailDirectory = rawMetadata.getFirstDirectoryOfType(ExifThumbnailDirectory.class);
            if (thumbnailDirectory.hasThumbnailData()) {
                thumbnail = thumbnailDirectory.getThumbnailData();
            } else {
                thumbnail = new byte[0];
            }
        } else {
            thumbnail = new byte[0];
        }
        final Map<String, Object> metadata = new HashMap<>(rawMetadata.getDirectoryCount());
        for (final Directory directory : rawMetadata.getDirectories()) {
            copy(directory, metadata);
            preProcess(context, directory, metadata);
        }
        return new Media(getFile(), fileName, context.getTemplate(), metadata, thumbnail);
    } catch (final ImageProcessingException e) {
        throw new MediaReaderException(e);
    }
}
 
開發者ID:edouardhue,項目名稱:comeon,代碼行數:26,代碼來源:PictureReader.java

示例14: getImageDate

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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());
  }
}
 
開發者ID:kotlinski,項目名稱:image-sort-master,代碼行數:25,代碼來源:FileDateInterpreter.java

示例15: updateImageInfo

import com.drew.imaging.ImageMetadataReader; //導入方法依賴的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);
}
 
開發者ID:nla,項目名稱:amberdb,代碼行數:23,代碼來源:Jp2Converter.java


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