Commit 139271d6 authored by Geoffrey Métais's avatar Geoffrey Métais

Do not rescale bitmap

It avoid to duplicate bitmap in memory.
Thus, inSampleSize must be a power of 2.
parent 86853da6
......@@ -274,7 +274,7 @@ public class AudioUtil {
coverPath = getCoverFromMediaStore(context, media);
// read (and scale?) the bitmap
cover = readCoverBitmap(context, coverPath, width);
cover = readCoverBitmap(coverPath, width);
// store cover into both cache
writeBitmap(cover, cachePath);
......@@ -302,7 +302,7 @@ public class AudioUtil {
}
}
private static Bitmap readCoverBitmap(Context context, String path, int dipWidth) {
private static Bitmap readCoverBitmap(String path, int dipWidth) {
Bitmap cover = null;
BitmapFactory.Options options = new BitmapFactory.Options();
int width = Util.convertDpToPx(dipWidth);
......@@ -313,20 +313,14 @@ public class AudioUtil {
if (options.outWidth > 0 && options.outHeight > 0) {
options.inJustDecodeBounds = false;
options.inSampleSize = 2;
options.inSampleSize = 1;
// Find the best decoding scale for the bitmap
while( options.outWidth / options.inSampleSize > width)
options.inSampleSize++;
options.inSampleSize--;
options.inSampleSize = options.inSampleSize * 2;
// Decode the file (with memory allocation this time)
cover = BitmapFactory.decodeFile(path, options);
if (cover != null && options.outWidth > width) {
int height = (int) (width * options.outHeight / ((double) options.outWidth));
cover = Bitmap.createScaledBitmap(cover, width, height, false);
}
}
return cover;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment