List of usage examples for org.apache.commons.imaging.formats.tiff.constants TiffTagConstants TIFF_TAG_IMAGE_DESCRIPTION
TagInfoAscii TIFF_TAG_IMAGE_DESCRIPTION
To view the source code for org.apache.commons.imaging.formats.tiff.constants TiffTagConstants TIFF_TAG_IMAGE_DESCRIPTION.
Click Source Link
From source file:org.openstreetmap.josm.plugins.mapillary.oauth.UploadUtils.java
/** * Returns a file containing the picture and an updated version of the EXIF * tags.//from w w w . j av a 2 s .c om * * @param image The image to be uploaded * @return A File object containing the picture and an updated version of the * EXIF tags. * @throws ImageReadException if there are errors reading the image from the file. * @throws IOException if there are errors getting the metadata from the file or writing * the output. * @throws ImageWriteException if there are errors writing the image in the file. */ static File updateFile(MapillaryImportedImage image) throws ImageReadException, IOException, ImageWriteException { TiffOutputSet outputSet = null; TiffOutputDirectory exifDirectory; TiffOutputDirectory gpsDirectory; TiffOutputDirectory rootDirectory; // If the image is imported, loads the rest of the EXIF data. JpegImageMetadata jpegMetadata = null; try { ImageMetadata metadata = Imaging.getMetadata(image.getFile()); jpegMetadata = (JpegImageMetadata) metadata; } catch (Exception e) { Main.warn(e); } if (null != jpegMetadata) { final TiffImageMetadata exif = jpegMetadata.getExif(); if (null != exif) { outputSet = exif.getOutputSet(); } } if (null == outputSet) { outputSet = new TiffOutputSet(); } gpsDirectory = outputSet.getOrCreateGPSDirectory(); exifDirectory = outputSet.getOrCreateExifDirectory(); rootDirectory = outputSet.getOrCreateRootDirectory(); gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF); gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF, GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF_VALUE_TRUE_NORTH); gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, RationalNumber.valueOf(image.getMovingCa())); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, image.getDate("yyyy/MM/dd HH:mm:ss")); // Removes the ImageDescription tag, that causes problems in the upload. rootDirectory.removeField(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION); outputSet.setGPSInDegrees(image.getMovingLatLon().lon(), image.getMovingLatLon().lat()); File tempFile = File.createTempFile("imagetoupload_" + c, ".tmp"); c++; OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile)); // Transforms the image into a byte array. ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(image.getImage(), "jpg", outputStream); byte[] imageBytes = outputStream.toByteArray(); new ExifRewriter().updateExifMetadataLossless(imageBytes, os, outputSet); os.close(); return tempFile; }