} finally {
Utils.closeSilently(cursor);
}
-
- // Fall back to checking EXIF tags in file.
- if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
- String mimeType = getMimeType(uri);
- if (!JPEG_MIME_TYPE.equals(mimeType)) {
- return ORI_NORMAL;
+ ExifInterface exif = new ExifInterface();
+ InputStream is = null;
+ // Fall back to checking EXIF tags in file or input stream.
+ try {
+ if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
+ String mimeType = getMimeType(uri);
+ if (!JPEG_MIME_TYPE.equals(mimeType)) {
+ return ORI_NORMAL;
+ }
+ String path = uri.getPath();
+ exif.readExif(path);
+ } else {
+ is = context.getContentResolver().openInputStream(uri);
+ exif.readExif(is);
}
- String path = uri.getPath();
- ExifInterface exif = new ExifInterface();
+ return parseExif(exif);
+ } catch (IOException e) {
+ Log.w(LOGTAG, "Failed to read EXIF orientation", e);
+ } finally {
try {
- exif.readExif(path);
- Integer tagval = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
- if (tagval != null) {
- int orientation = tagval;
- switch(orientation) {
- case ORI_NORMAL:
- case ORI_ROTATE_90:
- case ORI_ROTATE_180:
- case ORI_ROTATE_270:
- case ORI_FLIP_HOR:
- case ORI_FLIP_VERT:
- case ORI_TRANSPOSE:
- case ORI_TRANSVERSE:
- return orientation;
- default:
- return ORI_NORMAL;
- }
+ if (is != null) {
+ is.close();
}
} catch (IOException e) {
- Log.w(LOGTAG, "Failed to read EXIF orientation", e);
+ Log.w(LOGTAG, "Failed to close InputStream", e);
+ }
+ }
+ return ORI_NORMAL;
+ }
+
+ private static int parseExif(ExifInterface exif){
+ Integer tagval = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
+ if (tagval != null) {
+ int orientation = tagval;
+ switch(orientation) {
+ case ORI_NORMAL:
+ case ORI_ROTATE_90:
+ case ORI_ROTATE_180:
+ case ORI_ROTATE_270:
+ case ORI_FLIP_HOR:
+ case ORI_FLIP_VERT:
+ case ORI_TRANSPOSE:
+ case ORI_TRANSVERSE:
+ return orientation;
+ default:
+ return ORI_NORMAL;
}
}
return ORI_NORMAL;
// if we have a valid size
int w = (int) (bitmap.getWidth() * sizeFactor);
int h = (int) (bitmap.getHeight() * sizeFactor);
+ if (w == 0 || h == 0) {
+ w = 1;
+ h = 1;
+ }
bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
}
updateProgress();
return;
}
mEditing = true;
- int width = 0;
- int height = 0;
+ int width = 1;
+ int height = 1;
if (text.getId() == R.id.editableWidth) {
if (mWidthText.getText() != null) {
String value = String.valueOf(mWidthText.getText());
width = mOriginalBounds.width();
mWidthText.setText("" + width);
}
+ if (width <= 0) {
+ width = (int) Math.ceil(mRatio);
+ mWidthText.setText("" + width);
+ }
height = (int) (width / mRatio);
}
mHeightText.setText("" + height);
height = mOriginalBounds.height();
mHeightText.setText("" + height);
}
+ if (height <= 0) {
+ height = 1;
+ mHeightText.setText("" + height);
+ }
width = (int) (height * mRatio);
}
mWidthText.setText("" + width);