本文整理匯總了Java中com.drew.metadata.Metadata.getFirstDirectoryOfType方法的典型用法代碼示例。如果您正苦於以下問題:Java Metadata.getFirstDirectoryOfType方法的具體用法?Java Metadata.getFirstDirectoryOfType怎麽用?Java Metadata.getFirstDirectoryOfType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.drew.metadata.Metadata
的用法示例。
在下文中一共展示了Metadata.getFirstDirectoryOfType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOrientation
import com.drew.metadata.Metadata; //導入方法依賴的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 "";
}
示例2: write
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
/**
* Serializes the XmpDirectory component of <code>Metadata</code> into an <code>OutputStream</code>
* @param os Destination for the xmp data
* @param data populated metadata
* @return serialize success
*/
public static boolean write(OutputStream os, Metadata data)
{
XmpDirectory dir = data.getFirstDirectoryOfType(XmpDirectory.class);
if (dir == null)
return false;
XMPMeta meta = dir.getXMPMeta();
try
{
SerializeOptions so = new SerializeOptions().setOmitPacketWrapper(true);
XMPMetaFactory.serialize(meta, os, so);
}
catch (XMPException e)
{
e.printStackTrace();
return false;
}
return true;
}
示例3: 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);
}
}
示例4: 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 "";
}
}
示例5: getLocation
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
/**
* Checks for known Location in metadata
*
* @param metadata {@link Metadata} read from a file
* @return A {@link GeoLocation} object if successful, null otherwise
*/
public static GeoLocation getLocation(Metadata metadata) {
if(metadata == null) {
System.err.println("Metadata is null");
return null;
}
GeoLocation geoLocation = null;
// TODO:nics-247 Handle case where multiple GPS directories exist?
GpsDirectory geoDir = metadata.getFirstDirectoryOfType(GpsDirectory.class);
if(geoDir != null) {
geoLocation = geoDir.getGeoLocation();
} else
{
System.err.println("GeoLocation is null!");
}
return geoLocation;
}
示例6: getDate
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
/**
* Gets the File Last Modified Date from the Image metadata
*
* @param metadata
* @return
*/
public static Date getDate(Metadata metadata) {
if(metadata == null) {
return null;
}
Collection<FileMetadataDirectory> fileMetadataDirs = metadata.getDirectoriesOfType(FileMetadataDirectory.class);
if(fileMetadataDirs == null) {
return null;
}
Date date = null;
FileMetadataDirectory fileDir = metadata.getFirstDirectoryOfType(FileMetadataDirectory.class);
if(fileDir != null) {
date = fileDir.getDate(FileMetadataDirectory.TAG_FILE_MODIFIED_DATE);
}
// TODO:nics-247 other directory types have date, so to be thorough, could check more types
return date;
}
示例7: getOrientation
import com.drew.metadata.Metadata; //導入方法依賴的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;
}
}
示例8: addError
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
protected void addError(@NotNull String errorMessage, final @NotNull Metadata metadata) {
ErrorDirectory directory = metadata.getFirstDirectoryOfType(ErrorDirectory.class);
if (directory == null) {
metadata.addDirectory(new ErrorDirectory(errorMessage));
} else {
directory.addError(errorMessage);
}
}
示例9: read
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
public void read(@NotNull File file, @NotNull Metadata metadata) throws IOException
{
if (!file.isFile())
throw new IOException("File object must reference a file");
if (!file.exists())
throw new IOException("File does not exist");
if (!file.canRead())
throw new IOException("File is not readable");
FileSystemDirectory directory = metadata.getFirstDirectoryOfType(FileSystemDirectory.class);
if (directory == null) {
directory = new FileSystemDirectory();
metadata.addDirectory(directory);
}
directory.setString(FileSystemDirectory.TAG_FILE_NAME, file.getName());
directory.setLong(FileSystemDirectory.TAG_FILE_SIZE, file.length());
directory.setDate(FileSystemDirectory.TAG_FILE_MODIFIED_DATE, new Date(file.lastModified()));
}
示例10: 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.getFirstDirectoryOfType(ExifIFD0Directory.class);
ExifThumbnailDirectory thumbnailDirectory = metadata.getFirstDirectoryOfType(ExifThumbnailDirectory.class);
assertNotNull(ifd0Directory);
assertNotNull(thumbnailDirectory);
assertEquals(1, ifd0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION));
assertEquals(8, thumbnailDirectory.getInt(ExifThumbnailDirectory.TAG_ORIENTATION));
}
示例11: processBytes
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
@NotNull
public static PsdHeaderDirectory processBytes(@NotNull String file) throws Exception
{
Metadata metadata = new Metadata();
InputStream stream = new FileInputStream(new File(file));
try {
new PsdReader().extract(new StreamReader(stream), metadata);
} catch (Exception e) {
stream.close();
throw e;
}
PsdHeaderDirectory directory = metadata.getFirstDirectoryOfType(PsdHeaderDirectory.class);
assertNotNull(directory);
return directory;
}
示例12: getJpegData
import com.drew.metadata.Metadata; //導入方法依賴的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();
}
}
示例13: addFile
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
private void addFile(Path file) {
try {
io.getOut().println(file.toString());
Metadata metadata = ImageMetadataReader.readMetadata(file.toFile());
ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
if (directory != null) {
addPhoto(directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL),
file);
}
} catch (ImageProcessingException | IOException | SQLException ex) {
// Swallow
}
}
示例14: calculateJPEGSubsampling
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
/**
* Calculates the J:a:b chroma subsampling notation from a {@link Metadata}
* instance generated from a JPEG image. If the non-luminance components
* have different subsampling values or the calculation is impossible,
* {@link Double#NaN} will be returned for all factors.
*
* @param metadata the {@link Metadata} instance from which to calculate.
* @return A {@link JPEGSubsamplingNotation} with the result.
*/
public static JPEGSubsamplingNotation calculateJPEGSubsampling(Metadata metadata) {
if (metadata == null) {
throw new NullPointerException("metadata cannot be null");
}
JpegDirectory directory = metadata.getFirstDirectoryOfType(JpegDirectory.class);
if (directory == null) {
return new JPEGSubsamplingNotation(Double.NaN, Double.NaN, Double.NaN);
}
return calculateJPEGSubsampling(directory);
}
示例15: getExifDate
import com.drew.metadata.Metadata; //導入方法依賴的package包/類
private Date getExifDate(byte[] imgRaw) throws ImageProcessingException, IOException {
Metadata metadata = ImageMetadataReader.readMetadata(
new BufferedInputStream(new ByteArrayInputStream(imgRaw)));
ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
if (directory == null) {
return null;
}
return directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
}