@@ -164,27 +164,7 @@ private boolean crop() throws IOException {
164
164
if (shouldCrop ) {
165
165
saveImage (Bitmap .createBitmap (mViewBitmap , cropOffsetX , cropOffsetY , mCroppedImageWidth , mCroppedImageHeight ));
166
166
if (mCompressFormat .equals (Bitmap .CompressFormat .JPEG )) {
167
- boolean hasImageInputUriContentSchema = hasContentScheme (mImageInputUri );
168
- boolean hasImageOutputUriContentSchema = hasContentScheme (mImageOutputUri );
169
- if (hasImageInputUriContentSchema && hasImageOutputUriContentSchema ) {
170
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
171
- ImageHeaderParser .copyExif (context , mCroppedImageWidth , mCroppedImageHeight , mImageInputUri , mImageOutputUri );
172
- } else {
173
- Log .e (TAG , "It is not possible to write exif info into file represented by \" content\" Uri if Android < LOLLIPOP" );
174
- }
175
- } else if (hasImageInputUriContentSchema ) {
176
- ImageHeaderParser .copyExif (context , mCroppedImageWidth , mCroppedImageHeight , mImageInputUri , mImageOutputPath );
177
- } else if (hasImageOutputUriContentSchema ) {
178
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
179
- ExifInterface originalExif = new ExifInterface (mImageInputPath );
180
- ImageHeaderParser .copyExif (context , originalExif , mCroppedImageWidth , mCroppedImageHeight , mImageOutputUri );
181
- } else {
182
- Log .e (TAG , "It is not possible to write exif info into file represented by \" content\" Uri if Android < LOLLIPOP" );
183
- }
184
- } else {
185
- ExifInterface originalExif = new ExifInterface (mImageInputPath );
186
- ImageHeaderParser .copyExif (originalExif , mCroppedImageWidth , mCroppedImageHeight , mImageOutputPath );
187
- }
167
+ copyExifForOutputFile (context );
188
168
}
189
169
return true ;
190
170
} else {
@@ -193,8 +173,35 @@ private boolean crop() throws IOException {
193
173
}
194
174
}
195
175
196
- private boolean hasContentScheme (Uri uri ) {
197
- return uri != null && CONTENT_SCHEME .equals (uri .getScheme ());
176
+ private void copyExifForOutputFile (Context context ) throws IOException {
177
+ boolean hasImageInputUriContentSchema = BitmapLoadUtils .hasContentScheme (mImageInputUri );
178
+ boolean hasImageOutputUriContentSchema = BitmapLoadUtils .hasContentScheme (mImageOutputUri );
179
+ /*
180
+ * ImageHeaderParser.copyExif with output uri as a parameter
181
+ * uses ExifInterface constructor with FileDescriptor param for overriding output file exif info,
182
+ * which doesn't support ExitInterface.saveAttributes call for SDK lower than 21.
183
+ *
184
+ * See documentation for ImageHeaderParser.copyExif and ExifInterface.saveAttributes implementation.
185
+ */
186
+ if (hasImageInputUriContentSchema && hasImageOutputUriContentSchema ) {
187
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
188
+ ImageHeaderParser .copyExif (context , mCroppedImageWidth , mCroppedImageHeight , mImageInputUri , mImageOutputUri );
189
+ } else {
190
+ Log .e (TAG , "It is not possible to write exif info into file represented by \" content\" Uri if Android < LOLLIPOP" );
191
+ }
192
+ } else if (hasImageInputUriContentSchema ) {
193
+ ImageHeaderParser .copyExif (context , mCroppedImageWidth , mCroppedImageHeight , mImageInputUri , mImageOutputPath );
194
+ } else if (hasImageOutputUriContentSchema ) {
195
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
196
+ ExifInterface originalExif = new ExifInterface (mImageInputPath );
197
+ ImageHeaderParser .copyExif (context , originalExif , mCroppedImageWidth , mCroppedImageHeight , mImageOutputUri );
198
+ } else {
199
+ Log .e (TAG , "It is not possible to write exif info into file represented by \" content\" Uri if Android < LOLLIPOP" );
200
+ }
201
+ } else {
202
+ ExifInterface originalExif = new ExifInterface (mImageInputPath );
203
+ ImageHeaderParser .copyExif (originalExif , mCroppedImageWidth , mCroppedImageHeight , mImageOutputPath );
204
+ }
198
205
}
199
206
200
207
private void saveImage (@ NonNull Bitmap croppedBitmap ) {
@@ -244,7 +251,7 @@ protected void onPostExecute(@Nullable Throwable t) {
244
251
if (t == null ) {
245
252
Uri uri ;
246
253
247
- if (hasContentScheme (mImageOutputUri )) {
254
+ if (BitmapLoadUtils . hasContentScheme (mImageOutputUri )) {
248
255
uri = mImageOutputUri ;
249
256
} else {
250
257
uri = Uri .fromFile (new File (mImageOutputPath ));
0 commit comments