本文整理匯總了Java中com.drew.imaging.ImageProcessingException類的典型用法代碼示例。如果您正苦於以下問題:Java ImageProcessingException類的具體用法?Java ImageProcessingException怎麽用?Java ImageProcessingException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ImageProcessingException類屬於com.drew.imaging包,在下文中一共展示了ImageProcessingException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readExif
import com.drew.imaging.ImageProcessingException; //導入依賴的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;
}
示例2: getOrientation
import com.drew.imaging.ImageProcessingException; //導入依賴的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.imaging.ImageProcessingException; //導入依賴的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: getDateFromImgEXIF
import com.drew.imaging.ImageProcessingException; //導入依賴的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;
}
示例5: getExifDate
import com.drew.imaging.ImageProcessingException; //導入依賴的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 "";
}
}
示例6: nacti
import com.drew.imaging.ImageProcessingException; //導入依賴的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: main
import com.drew.imaging.ImageProcessingException; //導入依賴的package包/類
public static void main(String args[]) throws IOException, ImageProcessingException {
String tiffstr = utilities.BrowserDialogs.chooseFile();
InputStream is = new BufferedInputStream(new FileInputStream(tiffstr));
SeekableStream seekstr = new FileCacheSeekableStream(is);
TIFFDirectory tiffdir = new TIFFDirectory(seekstr, 0);
for (int i = 0; i < tiffdir.getNumEntries(); i++) {
// System.out.println(i);
// System.out.println(tiffdir.getField(i));
}
boolean cSB = seekstr.canSeekBackwards();
// System.out.println(cSB);
File tifffile = new File(tiffstr);
getImageTiffMetadata(tifffile);
getExifTiffData(tifffile);
}
示例8: getOrientation
import com.drew.imaging.ImageProcessingException; //導入依賴的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;
}
}
示例9: nactiKdyzUmis
import com.drew.imaging.ImageProcessingException; //導入依賴的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);
}
}
示例10: buildMedia
import com.drew.imaging.ImageProcessingException; //導入依賴的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);
}
}
示例11: getImageDate
import com.drew.imaging.ImageProcessingException; //導入依賴的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());
}
}
示例12: getJpegData
import com.drew.imaging.ImageProcessingException; //導入依賴的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: originalImageMetaData
import com.drew.imaging.ImageProcessingException; //導入依賴的package包/類
private Metadata originalImageMetaData() throws ImageProcessingException, IOException {
if(this.originalImageMetaData == null) {//this is expensive, don't do it more than once
originalImageMetaData = ImageMetadataReader.readMetadata(
new BufferedInputStream(new ByteArrayInputStream(originalImageData)),
originalImageData.length
);
}
return originalImageMetaData;
}
示例14: addFile
import com.drew.imaging.ImageProcessingException; //導入依賴的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
}
}
示例15: getExifDate
import com.drew.imaging.ImageProcessingException; //導入依賴的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);
}