small improvements for MediaUtils

This commit is contained in:
Conny Duck 2018-08-15 11:06:54 +02:00
parent ef1fa0ca94
commit c38d2ad25e
1 changed files with 5 additions and 9 deletions

View File

@ -65,7 +65,7 @@ public class MediaUtils {
* Fetches the size of the media represented by the given URI, assuming it is openable and * Fetches the size of the media represented by the given URI, assuming it is openable and
* the ContentResolver is able to resolve it. * the ContentResolver is able to resolve it.
* *
* @return the size of the media or {@link MediaUtils#MEDIA_SIZE_UNKNOWN} * @return the size of the media in bytes or {@link MediaUtils#MEDIA_SIZE_UNKNOWN}
*/ */
public static long getMediaSize(@NonNull ContentResolver contentResolver, @Nullable Uri uri) { public static long getMediaSize(@NonNull ContentResolver contentResolver, @Nullable Uri uri) {
if(uri == null) return MEDIA_SIZE_UNKNOWN; if(uri == null) return MEDIA_SIZE_UNKNOWN;
@ -125,14 +125,12 @@ public class MediaUtils {
} }
@Nullable @Nullable
public static Bitmap getImageThumbnail(ContentResolver contentResolver, Uri uri, public static Bitmap getImageThumbnail(ContentResolver contentResolver, Uri uri, @Px int thumbnailSize) {
@Px int thumbnailSize) {
Bitmap source = getSampledBitmap(contentResolver, uri, thumbnailSize, thumbnailSize); Bitmap source = getSampledBitmap(contentResolver, uri, thumbnailSize, thumbnailSize);
if(source != null) { if(source == null) {
return ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
} else {
return null; return null;
} }
return ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
} }
@Nullable @Nullable
@ -143,9 +141,7 @@ public class MediaUtils {
if (source == null) { if (source == null) {
return null; return null;
} }
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize); return ThumbnailUtils.extractThumbnail(source, thumbnailSize, thumbnailSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
source.recycle();
return bitmap;
} }
public static long getImageSquarePixels(ContentResolver contentResolver, Uri uri) throws FileNotFoundException { public static long getImageSquarePixels(ContentResolver contentResolver, Uri uri) throws FileNotFoundException {