diff options
-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 | ||||
-rw-r--r-- | src_pd/com/android/gallery3d/picasasource/PicasaSource.java | 4 |
4 files changed, 43 insertions, 21 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; diff --git a/src_pd/com/android/gallery3d/picasasource/PicasaSource.java b/src_pd/com/android/gallery3d/picasasource/PicasaSource.java index f8490676f..041829169 100644 --- a/src_pd/com/android/gallery3d/picasasource/PicasaSource.java +++ b/src_pd/com/android/gallery3d/picasasource/PicasaSource.java @@ -19,7 +19,6 @@ package com.android.gallery3d.picasasource; import android.app.Activity; import android.app.Dialog; import android.content.Context; -import android.media.ExifInterface; import android.os.ParcelFileDescriptor; import com.android.gallery3d.app.GalleryApp; @@ -29,6 +28,7 @@ import com.android.gallery3d.data.MediaSet; import com.android.gallery3d.data.MediaSource; import com.android.gallery3d.data.Path; import com.android.gallery3d.data.PathMatcher; +import com.android.gallery3d.exif.ExifData; import java.io.FileNotFoundException; @@ -143,7 +143,7 @@ public class PicasaSource extends MediaSource { public static void onPackageChanged(Context context, String packageName) {/*do nothing*/} - public static void extractExifValues(MediaObject item, ExifInterface exif) {/*do nothing*/} + public static void extractExifValues(MediaObject item, ExifData exif) {/*do nothing*/} public static Dialog getVersionCheckDialog(Activity activity){ return null; |