List of usage examples for org.apache.commons.imaging ImageReadException ImageReadException
public ImageReadException(final String s)
From source file:com.moorestudio.seniorimageprocessing.SeniorSorter.java
public void getTimestampData() throws ImageReadException, IOException, ParseException { int numImages = imageData.size(); for (File image : imageData.keySet()) { IImageMetadata metadata = getMetadata(image); if (metadata instanceof JpegImageMetadata) { JpegImageMetadata md = (JpegImageMetadata) metadata; String dateTime = md.findEXIFValue(TiffTagConstants.TIFF_TAG_DATE_TIME).getStringValue(); //if the dateTime is null, then throw an error if (dateTime == null || dateTime.isEmpty()) { throw new ImageReadException("Images do not contain the EXIF date information."); } else { //convert from EXIF format to a date SimpleDateFormat dateParser = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); imageData.put(image, dateParser.parse(dateTime).getTime()); }//ww w.j a v a 2 s.co m //update the gui parent.addProgress((.125 / parent.numThreads) / numImages); } else { throw new ImageReadException("Images do not contain the EXIF date information."); } } }
From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java
private void setGeocoding(final Path aTargetFile) throws IOException, ImageReadException, ImageWriteException { final Path sourceFile = picture.getFile(); final PhotoshopApp13Data photoshopMetadata = getPhotoshopMetadata(sourceFile); if (photoshopMetadata == null) { throw new ImageReadException("Could not obtain photoshop metadata"); }/* w w w . j av a 2 s . c om*/ try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(aTargetFile.toFile()))) { final Geocoding geocoding = picture.getGeocoding(); final EnumSet<IptcTypes> filterTypes = EnumSet.noneOf(IptcTypes.class); filterTypes.add(IptcTypes.CONTENT_LOCATION_NAME); filterTypes.add(IptcTypes.CITY); filterTypes.add(IptcTypes.SUBLOCATION); filterTypes.add(IptcTypes.PROVINCE_STATE); filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE); filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME); final List<IptcRecord> records = photoshopMetadata.getRecords(); final Iterator<IptcRecord> iter = records.iterator(); while (iter.hasNext()) { final IptcRecord record = iter.next(); final IptcType type = record.iptcType; if (filterTypes.contains(type)) { iter.remove(); } } records.add(new IptcRecord(IptcTypes.CONTENT_LOCATION_NAME, geocoding != null ? geocoding.getLocationName() : "")); records.add(new IptcRecord(IptcTypes.CITY, geocoding != null ? geocoding.getCity() : "")); records.add(new IptcRecord(IptcTypes.SUBLOCATION, geocoding != null ? geocoding.getSublocation() : "")); records.add(new IptcRecord(IptcTypes.PROVINCE_STATE, geocoding != null ? geocoding.getProvinceState() : "")); records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE, geocoding != null ? geocoding.getCountryCode() : "")); records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME, geocoding != null ? geocoding.getCountryName() : "")); final List<IptcBlock> rawBlocks = photoshopMetadata.getRawBlocks(); new JpegIptcRewriter().writeIPTC(sourceFile.toFile(), os, new PhotoshopApp13Data(records, rawBlocks)); } }