diff options
author | Earl Ou <shunhsingou@google.com> | 2012-08-30 12:02:43 +0800 |
---|---|---|
committer | Earl Ou <shunhsingou@google.com> | 2012-08-31 09:23:26 +0800 |
commit | 1c6566dfa563ece622df26a851e10c1c3b371a52 (patch) | |
tree | 51b7d3fd30c528097e449ea7a47ecf17d8fde2f6 /src | |
parent | afebbfa1b19f70f5c197e781071fadaf560d778d (diff) | |
download | android_packages_apps_Snap-1c6566dfa563ece622df26a851e10c1c3b371a52.tar.gz android_packages_apps_Snap-1c6566dfa563ece622df26a851e10c1c3b371a52.tar.bz2 android_packages_apps_Snap-1c6566dfa563ece622df26a851e10c1c3b371a52.zip |
Save EXIF info to cropped picasa image with the new EXIF lib.
Bug:5248023
Change-Id: I35f401826f4fa586e9899e3ca5f5f9b9ab39b28e
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/gallery3d/app/CropImage.java | 22 | ||||
-rw-r--r-- | src/com/android/gallery3d/exif/ExifData.java | 36 | ||||
-rw-r--r-- | src/com/android/gallery3d/exif/ExifTag.java | 2 |
3 files changed, 41 insertions, 19 deletions
diff --git a/src/com/android/gallery3d/app/CropImage.java b/src/com/android/gallery3d/app/CropImage.java index 70d08730e..21ce98388 100644 --- a/src/com/android/gallery3d/app/CropImage.java +++ b/src/com/android/gallery3d/app/CropImage.java @@ -30,7 +30,6 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; -import android.media.ExifInterface; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -82,6 +81,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.ByteOrder; import java.text.SimpleDateFormat; import java.util.Date; @@ -421,15 +421,14 @@ public class CropImage extends AbstractGalleryActivity { if (!DOWNLOAD_BUCKET.isDirectory() && !DOWNLOAD_BUCKET.mkdirs()) { throw new RuntimeException("cannot create download folder"); } - String filename = PicasaSource.getImageTitle(mMediaItem); int pos = filename.lastIndexOf('.'); if (pos >= 0) filename = filename.substring(0, pos); - File output = saveMedia(jc, cropped, DOWNLOAD_BUCKET, filename, null); + ExifData exifData = new ExifData(ByteOrder.BIG_ENDIAN); + PicasaSource.extractExifValues(mMediaItem, exifData); + File output = saveMedia(jc, cropped, DOWNLOAD_BUCKET, filename, exifData); if (output == null) return null; - copyExif(mMediaItem, output.getAbsolutePath(), cropped.getWidth(), cropped.getHeight()); - long now = System.currentTimeMillis() / 1000; ContentValues values = new ContentValues(); values.put(Images.Media.TITLE, PicasaSource.getImageTitle(mMediaItem)); @@ -1000,17 +999,4 @@ public class CropImage extends AbstractGalleryActivity { : mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc); } } - - private static void copyExif(MediaItem item, String destination, int newWidth, int newHeight) { - try { - ExifInterface newExif = new ExifInterface(destination); - PicasaSource.extractExifValues(item, newExif); - newExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(newWidth)); - newExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(newHeight)); - newExif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(0)); - newExif.saveAttributes(); - } catch (Throwable t) { - Log.w(TAG, "cannot copy exif: " + item, t); - } - } } diff --git a/src/com/android/gallery3d/exif/ExifData.java b/src/com/android/gallery3d/exif/ExifData.java index 776f77a65..0251c74b1 100644 --- a/src/com/android/gallery3d/exif/ExifData.java +++ b/src/com/android/gallery3d/exif/ExifData.java @@ -142,4 +142,40 @@ public class ExifData { } return false; } + + public void addGpsTags(double latitude, double longitude) { + IfdData gpsIfd = getIfdData(IfdId.TYPE_IFD_GPS); + if (gpsIfd == null) { + gpsIfd = new IfdData(IfdId.TYPE_IFD_GPS); + addIfdData(gpsIfd); + } + ExifTag latTag = new ExifTag(ExifTag.GPS_TAG.TAG_GPS_LATITUDE, ExifTag.TYPE_RATIONAL, + 3, IfdId.TYPE_IFD_GPS); + ExifTag longTag = new ExifTag(ExifTag.GPS_TAG.TAG_GPS_LONGITUDE, ExifTag.TYPE_RATIONAL, + 3, IfdId.TYPE_IFD_GPS); + ExifTag latRefTag = new ExifTag(ExifTag.GPS_TAG.TAG_GPS_LATITUDE_REF, + ExifTag.TYPE_ASCII, 2, IfdId.TYPE_IFD_GPS); + ExifTag longRefTag = new ExifTag(ExifTag.GPS_TAG.TAG_GPS_LONGITUDE_REF, + ExifTag.TYPE_ASCII, 2, IfdId.TYPE_IFD_GPS); + latTag.setValue(toExifLatLong(latitude)); + longTag.setValue(toExifLatLong(longitude)); + latRefTag.setValue(latitude >= 0 ? "N" : "S"); + longRefTag.setValue(longitude >= 0 ? "E" : "W"); + gpsIfd.setTag(latTag); + gpsIfd.setTag(longTag); + gpsIfd.setTag(latRefTag); + gpsIfd.setTag(longRefTag); + } + + private static Rational[] toExifLatLong(double value) { + // convert to the format dd/1 mm/1 ssss/100 + value = Math.abs(value); + int degrees = (int) value; + value = (value - degrees) * 60; + int minutes = (int) value; + value = (value - minutes) * 6000; + int seconds = (int) value; + return new Rational[] { + new Rational(degrees, 1), new Rational(minutes, 1), new Rational(seconds, 100)}; + } }
\ No newline at end of file diff --git a/src/com/android/gallery3d/exif/ExifTag.java b/src/com/android/gallery3d/exif/ExifTag.java index fad47d678..35e308d77 100644 --- a/src/com/android/gallery3d/exif/ExifTag.java +++ b/src/com/android/gallery3d/exif/ExifTag.java @@ -369,7 +369,7 @@ public class ExifTag { private Object mValue; private int mOffset; - ExifTag(short tagId, short type, int componentCount, int ifd) { + public ExifTag(short tagId, short type, int componentCount, int ifd) { mTagId = tagId; mDataType = type; mComponentCount = componentCount; |