/** * Returns the ExifTag in that tag's default IFD for a defined tag constant * or null if none exists. * * @param tagId a defined tag constant, e.g. {@link #TAG_IMAGE_WIDTH}. * @return an {@link ExifTag} or null if none exists. */ public ExifTag getTag( int tagId ) { int ifdId = getDefinedTagDefaultIfd( tagId ); return getTag( tagId, ifdId ); }
/** * @see #getTagValue */ public Integer getTagIntValue( int tagId ) { int ifdId = getDefinedTagDefaultIfd( tagId ); return getTagIntValue( tagId, ifdId ); }
protected ExifTag buildUninitializedTag( int tagId ) { int info = getTagInfo().get( tagId ); if( info == 0 ) { return null; } short type = getTypeFromInfo( info ); int definedCount = getComponentCountFromInfo( info ); boolean hasDefinedCount = ( definedCount != ExifTag.SIZE_UNDEFINED ); int ifdId = getTrueIfd( tagId ); return new ExifTag( getTrueTagKey( tagId ), type, definedCount, ifdId, hasDefinedCount ); }
/** * Creates a tag for a defined tag constant in the tag's default IFD. * * @param tagId a tag constant, e.g. {@link #TAG_IMAGE_WIDTH}. * @param val the tag's value. * @return an ExifTag object. */ public ExifTag buildTag( int tagId, Object val ) { int ifdId = getTrueIfd( tagId ); return buildTag( tagId, ifdId, val ); }
mExif = new ExifInterface(); List<ExifTag> all_tags = null; long t1 = System.currentTimeMillis(); try { mExif.readExif( stream, ExifInterface.Options.OPTION_ALL ); } catch( IOException e ) { e.printStackTrace(); all_tags = mExif.getAllTags(); Log.d(LOG_TAG, "total tags: " + (all_tags != null ? all_tags.size() : 0)); if( mExif.getQualityGuess() > 0 ) { string.append( "<b>JPEG quality:</b> " + mExif.getQualityGuess() + "<br>" ); int[] imagesize = mExif.getImageSize(); if( imagesize[0] > 0 && imagesize[1] > 0 ) { string.append( "<b>Image Size: </b>" + imagesize[0] + "x" + imagesize[1] + "<br>" ); List<ExifTag> tags = mExif.getTagsForTagId( mExif.getTrueTagKey( ExifInterface.TAG_ORIENTATION ) ); Log.d( LOG_TAG, "tags: " + tags ); string.append( "<b>Total tags parsed:</b> " + mTagsCount + "<br>" ); string.append( "<b>Remaining tags:</b> " + ( all_tags != null ? all_tags.size() : 0 ) + "<br>" ); string.append( "<b>Has Thumbnail:</b> " + mExif.hasThumbnail() + "<br>" ); ExifTag tag = mExif.getTag( ExifInterface.TAG_EXIF_VERSION ); if( null != tag ) { string.append( "<b>Exif version: </b> " + tag.getValueAsString() + "<br>" );
ExifInterface exif = new ExifInterface(); exif.setTags( mExif.getAllTags() ); exif.setCompressedThumbnail( mExif.getThumbnail() ); exif.writeExif( dst_file.getAbsolutePath() );
/** * Creates a tag for a defined tag constant in a given IFD if that IFD is * allowed for the tag. This method will fail anytime the appropriate * {@link ExifTag#setValue} for this tag's datatype would fail. * * @param tagId a tag constant, e.g. {@link #TAG_IMAGE_WIDTH}. * @param ifdId the IFD that the tag should be in. * @param val the value of the tag to set. * @return an ExifTag object or null if one could not be constructed. * @see #buildTag */ public ExifTag buildTag( int tagId, int ifdId, Object val ) { int info = getTagInfo().get( tagId ); if( info == 0 || val == null ) { return null; } short type = getTypeFromInfo( info ); int definedCount = getComponentCountFromInfo( info ); boolean hasDefinedCount = ( definedCount != ExifTag.SIZE_UNDEFINED ); if( ! ExifInterface.isIfdAllowed( info, ifdId ) ) { return null; } ExifTag t = new ExifTag( getTrueTagKey( tagId ), type, definedCount, ifdId, hasDefinedCount ); if( ! t.setValue( val ) ) { return null; } return t; }
/** * Gets a tag value for an IFD other than the tag's default. * * @see #getTagValue */ public Object getTagValue( int tagId, int ifdId ) { ExifTag t = getTag( tagId, ifdId ); return ( t == null ) ? null : t.getValue(); }
/** * Removes the ExifTag for a tag constant from the given IFD. * * @param tagId a tag constant, e.g. {@link #TAG_IMAGE_WIDTH}. * @param ifdId the IFD of the ExifTag to remove. */ public void deleteTag( int tagId, int ifdId ) { mData.removeTag( getTrueTagKey( tagId ), ifdId ); }
/** * Creates and sets all to the GPS tags for a give latitude and longitude. * * @param latitude a GPS latitude coordinate. * @param longitude a GPS longitude coordinate. * @return true if success, false if they could not be created or set. */ @SuppressWarnings( "unused" ) public boolean addGpsTags( double latitude, double longitude ) { ExifTag latTag = buildTag( TAG_GPS_LATITUDE, toExifLatLong( latitude ) ); ExifTag longTag = buildTag( TAG_GPS_LONGITUDE, toExifLatLong( longitude ) ); ExifTag latRefTag = buildTag( TAG_GPS_LATITUDE_REF, latitude >= 0 ? GpsLatitudeRef.NORTH : GpsLatitudeRef.SOUTH ); ExifTag longRefTag = buildTag( TAG_GPS_LONGITUDE_REF, longitude >= 0 ? GpsLongitudeRef.EAST : GpsLongitudeRef.WEST ); if( latTag == null || longTag == null || latRefTag == null || longRefTag == null ) { return false; } setTag( latTag ); setTag( longTag ); setTag( latRefTag ); setTag( longRefTag ); return true; }
ExifInterface src_exif = new ExifInterface(); src_exif.readExif( input, 0 );
/** * Creates, formats, and sets the DateTimeStamp tag for one of: * {@link #TAG_DATE_TIME}, {@link #TAG_DATE_TIME_DIGITIZED}, * {@link #TAG_DATE_TIME_ORIGINAL}. * * @param tagId one of the DateTimeStamp tags. * @param timestamp a timestamp to format. * @param timezone a TimeZone object. * @return true if success, false if the tag could not be set. */ public boolean addDateTimeStampTag( int tagId, long timestamp, TimeZone timezone ) { if( tagId == TAG_DATE_TIME || tagId == TAG_DATE_TIME_DIGITIZED || tagId == TAG_DATE_TIME_ORIGINAL ) { mDateTimeStampFormat.setTimeZone( timezone ); ExifTag t = buildTag( tagId, mDateTimeStampFormat.format( timestamp ) ); if( t == null ) { return false; } setTag( t ); } else { return false; } return true; }
/** * Reads the exif tags from a file, clearing this ExifInterface object's * existing exif tags. * * @param inFileName a string representing the filepath to jpeg file. * @param options bit flag which defines which type of tags to process, see {@link it.sephiroth.android.library.exif2.ExifInterface.Options} * @see #readExif(java.io.InputStream, int) * @throws java.io.IOException */ @SuppressWarnings( "unused" ) public void readExif( String inFileName, int options ) throws IOException { if( inFileName == null ) { throw new IllegalArgumentException( NULL_ARGUMENT_STRING ); } InputStream is = null; try { is = new BufferedInputStream( new FileInputStream( inFileName ) ); readExif( is, options ); } catch( IOException e ) { closeSilently( is ); throw e; } is.close(); }
ExifTag exifOffsetTag = mInterface.buildUninitializedTag( ExifInterface.TAG_EXIF_IFD ); if( exifOffsetTag == null ) { throw new IOException( "No definition for crucial exif tag: " + ExifInterface.TAG_EXIF_IFD ); ExifTag gpsOffsetTag = mInterface.buildUninitializedTag( ExifInterface.TAG_GPS_IFD ); if( gpsOffsetTag == null ) { throw new IOException( "No definition for crucial exif tag: " + ExifInterface.TAG_GPS_IFD ); ExifTag interOffsetTag = mInterface.buildUninitializedTag( ExifInterface.TAG_INTEROPERABILITY_IFD ); if( interOffsetTag == null ) { throw new IOException( "No definition for crucial exif tag: " + ExifInterface.TAG_INTEROPERABILITY_IFD ); ExifTag offsetTag = mInterface.buildUninitializedTag( ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT ); if( offsetTag == null ) { throw new IOException( "No definition for crucial exif tag: " + ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT ); ExifTag lengthTag = mInterface.buildUninitializedTag( ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH ); if( lengthTag == null ) { throw new IOException( "No definition for crucial exif tag: " + ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH ); ifd1.removeTag( ExifInterface.getTrueTagKey( ExifInterface.TAG_STRIP_OFFSETS ) ); ifd1.removeTag( ExifInterface.getTrueTagKey( ExifInterface.TAG_STRIP_BYTE_COUNTS ) ); ExifTag offsetTag = mInterface.buildUninitializedTag( ExifInterface.TAG_STRIP_OFFSETS ); if( offsetTag == null ) { throw new IOException( "No definition for crucial exif tag: " + ExifInterface.TAG_STRIP_OFFSETS ); ExifTag lengthTag = mInterface.buildUninitializedTag( ExifInterface.TAG_STRIP_BYTE_COUNTS ); if( lengthTag == null ) {
@SuppressWarnings( "unused" ) public void writeExif( final Bitmap input, final String dstFilename, int quality ) throws IOException { Log.i( TAG, "writeExif: " + dstFilename ); // inpur is used *ONLY* to read the image uncompressed data // exif tags are not used here ByteArrayOutputStream out = new ByteArrayOutputStream(); input.compress( Bitmap.CompressFormat.JPEG, quality, out ); ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() ); out.close(); writeExif( in, dstFilename ); }
private String createStringFromIfFound( ExifInterface exif, int key, String label, final List<ExifTag> all_tags ) { String exifString = ""; ExifTag tag = exif.getTag( key ); if( null != tag ) { Date date = ExifInterface.getDateTime( tag.getValueAsString(), TimeZone.getDefault() ); if( null != date ) { exifString += java.text.DateFormat.getDateTimeInstance().format( date );
/** * Reads the exif tags from a byte array, clearing this ExifInterface * object's existing exif tags. * * @param jpeg a byte array containing a jpeg compressed image. * @param options bit flag which defines which type of tags to process, see {@link it.sephiroth.android.library.exif2.ExifInterface.Options} * @throws java.io.IOException * @see #readExif(java.io.InputStream, int) */ @SuppressWarnings( "unused" ) public void readExif( byte[] jpeg, int options ) throws IOException { readExif( new ByteArrayInputStream( jpeg ), options ); }
/** * Sets the thumbnail to be a jpeg compressed bitmap. Clears any prior * thumbnail. * * @param thumb a bitmap to compress to a jpeg thumbnail. * @return true if the thumbnail was set. */ @SuppressWarnings( "unused" ) public boolean setCompressedThumbnail( Bitmap thumb ) { ByteArrayOutputStream thumbnail = new ByteArrayOutputStream(); if( ! thumb.compress( Bitmap.CompressFormat.JPEG, 90, thumbnail ) ) { return false; } return setCompressedThumbnail( thumbnail.toByteArray() ); }
/** * Creates a tag for a defined tag constant in a given IFD if that IFD is * allowed for the tag. This method will fail anytime the appropriate * {@link ExifTag#setValue} for this tag's datatype would fail. * * @param tagId a tag constant, e.g. {@link #TAG_IMAGE_WIDTH}. * @param ifdId the IFD that the tag should be in. * @param val the value of the tag to set. * @return an ExifTag object or null if one could not be constructed. * @see #buildTag */ public ExifTag buildTag( int tagId, int ifdId, Object val ) { int info = getTagInfo().get( tagId ); if( info == 0 || val == null ) { return null; } short type = getTypeFromInfo( info ); int definedCount = getComponentCountFromInfo( info ); boolean hasDefinedCount = ( definedCount != ExifTag.SIZE_UNDEFINED ); if( ! ExifInterface.isIfdAllowed( info, ifdId ) ) { return null; } ExifTag t = new ExifTag( getTrueTagKey( tagId ), type, definedCount, ifdId, hasDefinedCount ); if( ! t.setValue( val ) ) { return null; } return t; }