diff --git a/iNaturalist/src/main/java/org/inaturalist/android/INaturalistServiceImplementation.java b/iNaturalist/src/main/java/org/inaturalist/android/INaturalistServiceImplementation.java index 68fe0ef5..34a1a5ef 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/INaturalistServiceImplementation.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/INaturalistServiceImplementation.java @@ -639,7 +639,7 @@ public void onTimezone(String timezoneName) { taxonSuggestions = getTaxonSuggestions(obsUrl, latitude, longitude, observedOn, suggestionSource, placeId, taxonId, placeLat, placeLng, limit, page); } else { // Local photo - Resize photo to 640x640 max, not using Lanczos - String resizedPhotoFilename = ImageUtils.resizeImage(mContext, obsFilename, null, 640, true); + String resizedPhotoFilename = ImageUtils.resizeImage(mContext, obsFilename, null, 640, true, false); if (resizedPhotoFilename != null) { taxonSuggestions = getTaxonSuggestions(resizedPhotoFilename, latitude, longitude, observedOn, suggestionSource, placeId, taxonId, placeLat, placeLng, limit, page); diff --git a/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java b/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java index 3454e45c..41633d19 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java @@ -353,19 +353,21 @@ public static Bitmap rotateImage(Bitmap bitmapImage, int orientation) { - public static String resizeImage(Context context, String path, Uri photoUri, int maxDimensions) { - return resizeImage(context, path, photoUri, maxDimensions, false); + public static String resizeImage(Context context, String path, Uri photoUri, int maxDimensions, boolean isCameraPhoto) { + return resizeImage(context, path, photoUri, maxDimensions, false, isCameraPhoto); } /** * Resizes an image to max size * @param path the path to the image filename (optional) * @param photoUri the original Uri of the image * @param noLanczos if True, will not use Lanczos to resize image (but rather bilinear resampling) + * @param isCameraPhoto if True, will not rotate photo orientation according to EXIF (photo taken by iNat camera itself) * @return the resized image - or original image if smaller than 2048x2048 */ - public static String resizeImage(Context context, String path, Uri photoUri, int maxDimensions, boolean noLanczos) { + public static String resizeImage(Context context, String path, Uri photoUri, int maxDimensions, boolean noLanczos, boolean isCameraPhoto) { InputStream is = null; BitmapFactory.Options options = new BitmapFactory.Options(); + Logger.tag(TAG).info("resizeImage: " + path + "/" + photoUri + ":" + isCameraPhoto); try { if (photoUri != null) { @@ -398,9 +400,11 @@ public static String resizeImage(Context context, String path, Uri photoUri, int int rotationDegrees = 0; - if (path != null && path.toLowerCase().endsWith("heic")) { + + if (path != null) { androidx.exifinterface.media.ExifInterface exif = new androidx.exifinterface.media.ExifInterface(path); rotationDegrees = exif.getRotationDegrees(); + Logger.tag(TAG).error("resizeImage: degrees: " + rotationDegrees); } if (photoUri != null) { @@ -471,17 +475,6 @@ public static String resizeImage(Context context, String path, Uri photoUri, int // BitmapFactory.decodeStream moves the reading cursor is.close(); - if (photoUri != null) { - is = context.getContentResolver().openInputStream(photoUri); - } else { - is = new FileInputStream(new File(path)); - } - - // Copy all EXIF data from original image into resized image - copyExifData(is, new File(imageFile.getAbsolutePath()), null); - - is.close(); - return imageFile.getAbsolutePath(); } catch (OutOfMemoryError e) { diff --git a/iNaturalist/src/main/java/org/inaturalist/android/ObservationEditor.java b/iNaturalist/src/main/java/org/inaturalist/android/ObservationEditor.java index cdc5d292..fafe54e6 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/ObservationEditor.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/ObservationEditor.java @@ -184,6 +184,7 @@ public class ObservationEditor extends Fragment { @State public boolean mIsCaptive = false; @State public boolean mChoseNewPhoto = false; @State public boolean mChoseNewSound = false; + @State public boolean mCameraPhotoTaken = false; private List mSharePhotos = null; @State public HashMap mOriginalPhotoPositions = null; @@ -1456,6 +1457,7 @@ public void onPermissionDenied() { // In case a new/existing photo was taken - make sure we won't retake it in case the activity pauses/resumes. mPictureTaken = true; + mCameraPhotoTaken = true; } private void chooseSound() { @@ -1504,6 +1506,7 @@ public void onPermissionDenied() { private void choosePhoto() { Logger.tag(TAG).debug("choosePhoto"); + mCameraPhotoTaken = false; if (!mApp.isExternalStoragePermissionGranted()) { Logger.tag(TAG).debug("choosePhoto - no storage permissions"); @@ -3581,7 +3584,7 @@ private Uri createObservationSoundForSound(Uri soundUri) { } private Uri createObservationPhotoForPhoto(Uri photoUri, int position, boolean isDuplicated) { - Logger.tag(TAG).debug("createObservationPhotoForPhoto: " + photoUri + ":" + position + ":" + isDuplicated); + Logger.tag(TAG).debug("createObservationPhotoForPhoto: " + photoUri + ":" + position + ":" + isDuplicated + ":" + mCameraPhotoTaken); mPhotosChanged = true; @@ -3613,7 +3616,7 @@ private Uri createObservationPhotoForPhoto(Uri photoUri, int position, boolean i } // Resize photo to 2048x2048 max - String resizedPhoto = ImageUtils.resizeImage(getActivity(), path, isDuplicated ? null : photoUri, 2048); + String resizedPhoto = ImageUtils.resizeImage(getActivity(), path, isDuplicated ? null : photoUri, 2048, mCameraPhotoTaken); if (resizedPhoto == null) { return null; @@ -3623,7 +3626,7 @@ private Uri createObservationPhotoForPhoto(Uri photoUri, int position, boolean i } // Save original-sized copy of the photo (so when cropping, we'll crop from the original sized photo) - String originalSizePhoto = ImageUtils.resizeImage(getActivity(), path, isDuplicated ? null : photoUri, Integer.MAX_VALUE); + String originalSizePhoto = ImageUtils.resizeImage(getActivity(), path, isDuplicated ? null : photoUri, Integer.MAX_VALUE, mCameraPhotoTaken); ObservationPhoto op = new ObservationPhoto(); diff --git a/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java b/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java index babeec97..dad0e01c 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java @@ -3795,7 +3795,7 @@ private Uri createObservationPhotoForPhoto(Uri photoUri, int position, boolean i } // Resize photo to 2048x2048 max - String resizedPhoto = ImageUtils.resizeImage(getActivity(), path, photoUri, 2048); + String resizedPhoto = ImageUtils.resizeImage(getActivity(), path, photoUri, 2048, false); if (resizedPhoto == null) { return null;