/**
* Loads a bitmap that has been downsampled using sampleSize from a given url.
*/
public static Bitmap loadDownsampledBitmap(Context context, Uri uri, int sampleSize) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
options.inSampleSize = sampleSize;
return loadBitmap(context, uri, options);
}
/**
* Returns the bitmap from the given uri loaded using the given options.
* Returns null on failure.
*/
public static Bitmap loadBitmap(Context context, Uri uri, BitmapFactory.Options o) {
if (uri == null || context == null) {
throw new IllegalArgumentException("bad argument to loadBitmap");
}
InputStream is = null;
try {
is = context.getContentResolver().openInputStream(uri);
return BitmapFactory.decodeStream(is, null, o);
} catch (FileNotFoundException e) {
Log.e(LOGTAG, "FileNotFoundException for " + uri, e);
} finally {
Utils.closeSilently(is);
}
return null;
}