use of android.support.media.ExifInterface in project AnExplorer by 1hakr.
the class DocumentsContract method openImageThumbnail.
/**
* Open the given image for thumbnail purposes, using any embedded EXIF
* thumbnail if available, and providing orientation hints from the parent
* image.
*
* @hide
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static AssetFileDescriptor openImageThumbnail(File file) throws FileNotFoundException {
final ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
Bundle extras = null;
if (!Utils.hasKitKat()) {
return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH);
}
try {
final ExifInterface exif = new ExifInterface(file.getAbsolutePath());
switch(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1)) {
case ExifInterface.ORIENTATION_ROTATE_90:
extras = new Bundle(1);
extras.putInt(EXTRA_ORIENTATION, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
extras = new Bundle(1);
extras.putInt(EXTRA_ORIENTATION, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
extras = new Bundle(1);
extras.putInt(EXTRA_ORIENTATION, 270);
break;
}
final long[] thumb = exif.getThumbnailRange();
if (thumb != null) {
return new AssetFileDescriptor(pfd, thumb[0], thumb[1], extras);
}
} catch (IOException e) {
CrashReportingManager.logException(e);
}
return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH, extras);
}
use of android.support.media.ExifInterface in project AnExplorer by 1hakr.
the class DocumentArchive method openDocumentThumbnail.
/**
* Opens a thumbnail of a file within an archive.
*/
public AssetFileDescriptor openDocumentThumbnail(String documentId, Point sizeHint, final CancellationSignal signal) throws FileNotFoundException {
final ParsedDocumentId parsedId = ParsedDocumentId.fromDocumentId(documentId, mIdDelimiter);
Preconditions.checkArgumentEquals(mDocumentId, parsedId.mArchiveId, "Mismatching document ID. Expected: %s, actual: %s.");
Preconditions.checkArgumentNotNull(parsedId.mPath, "Not a document within an archive.");
Preconditions.checkArgument(getDocumentType(documentId).startsWith("image/"), "Thumbnails only supported for image/* MIME type.");
final ZipEntry entry = mEntries.get(parsedId.mPath);
if (entry == null) {
throw new FileNotFoundException();
}
if (!Utils.hasKitKat()) {
return new AssetFileDescriptor(openDocument(documentId, "r", signal), 0, entry.getSize());
}
InputStream inputStream = null;
try {
inputStream = mZipFile.getInputStream(entry);
final ExifInterface exif = new ExifInterface(inputStream);
if (exif.hasThumbnail()) {
Bundle extras = null;
switch(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1)) {
case ExifInterface.ORIENTATION_ROTATE_90:
extras = new Bundle(1);
extras.putInt(DocumentsContract.EXTRA_ORIENTATION, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
extras = new Bundle(1);
extras.putInt(DocumentsContract.EXTRA_ORIENTATION, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
extras = new Bundle(1);
extras.putInt(DocumentsContract.EXTRA_ORIENTATION, 270);
break;
}
final long[] thumb = exif.getThumbnailRange();
if (thumb != null) {
return new AssetFileDescriptor(openDocument(documentId, "r", signal), thumb[0], thumb[1], extras);
}
}
} catch (IOException e) {
// Ignore the exception, as reading the EXIF may legally fail.
Log.e(TAG, "Failed to obtain thumbnail from EXIF.", e);
CrashReportingManager.logException(e);
} finally {
IoUtils.closeQuietly(inputStream);
}
return new AssetFileDescriptor(openDocument(documentId, "r", signal), 0, entry.getSize(), null);
}
use of android.support.media.ExifInterface in project Zom-Android by zom.
the class SecureMediaStore method getThumbnailFile.
public static Bitmap getThumbnailFile(Context context, Uri uri, int thumbnailSize) throws IOException {
InputStream is = context.getContentResolver().openInputStream(uri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inInputShareable = true;
options.inPurgeable = true;
BitmapFactory.decodeStream(is, null, options);
if ((options.outWidth == -1) || (options.outHeight == -1))
return null;
int originalSize = (options.outHeight > options.outWidth) ? options.outHeight : options.outWidth;
is.close();
is = context.getContentResolver().openInputStream(uri);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = calculateInSampleSize(options, thumbnailSize, thumbnailSize);
Bitmap scaledBitmap = BitmapFactory.decodeStream(is, null, opts);
is.close();
ExifInterface exif = new ExifInterface(context.getContentResolver().openInputStream(uri));
int orientationType = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int orientationD = 0;
if (orientationType == ExifInterface.ORIENTATION_ROTATE_90)
orientationD = 90;
else if (orientationType == ExifInterface.ORIENTATION_ROTATE_180)
orientationD = 180;
else if (orientationType == ExifInterface.ORIENTATION_ROTATE_270)
orientationD = 270;
if (orientationD != 0)
scaledBitmap = rotateBitmap(scaledBitmap, orientationD);
return scaledBitmap;
}
use of android.support.media.ExifInterface in project Zom-Android by zom.
the class SecureMediaStore method getImageOrientation.
public static int getImageOrientation(String imagePath) {
int rotate = 0;
try {
ExifInterface exif = new ExifInterface(imagePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return rotate;
}
use of android.support.media.ExifInterface in project muzei by romannurik.
the class RealRenderController method openDownloadedCurrentArtwork.
@Override
protected BitmapRegionLoader openDownloadedCurrentArtwork(boolean forceReload) {
// Load the stream
try {
// Check if there's rotation
int rotation = 0;
try (InputStream in = mContext.getContentResolver().openInputStream(MuzeiContract.Artwork.CONTENT_URI)) {
if (in == null) {
return null;
}
ExifInterface exifInterface = new ExifInterface(in);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotation = 270;
break;
}
} catch (IOException | StackOverflowError e) {
Log.w(TAG, "Couldn't open EXIF interface on artwork", e);
}
return BitmapRegionLoader.newInstance(mContext.getContentResolver().openInputStream(MuzeiContract.Artwork.CONTENT_URI), rotation);
} catch (IOException e) {
Log.e(TAG, "Error loading image", e);
return null;
}
}
Aggregations