summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2012-09-02 20:11:35 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-09-02 20:11:36 -0700
commit8a81312ec4065063ed69147a0340ab96d77b6d7d (patch)
tree8d8e89da25d1b22d1d6e90d49f9098bb7ca26749 /src
parent6661c4610254e81098dc67c087b69900a32f0f0d (diff)
parent1c6566dfa563ece622df26a851e10c1c3b371a52 (diff)
downloadandroid_packages_apps_Snap-8a81312ec4065063ed69147a0340ab96d77b6d7d.tar.gz
android_packages_apps_Snap-8a81312ec4065063ed69147a0340ab96d77b6d7d.tar.bz2
android_packages_apps_Snap-8a81312ec4065063ed69147a0340ab96d77b6d7d.zip
Merge "Save EXIF info to cropped picasa image with the new EXIF lib." into gb-ub-photos-arches
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/app/CropImage.java22
-rw-r--r--src/com/android/gallery3d/exif/ExifData.java36
-rw-r--r--src/com/android/gallery3d/exif/ExifTag.java2
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;