[Android] [PATCH 1/4] Do not rescale bitmap
Geoffrey Métais
geoffrey.metais at gmail.com
Thu Apr 2 16:54:44 CEST 2015
It avoid to duplicate bitmap in memory.
Thus, inSampleSize must be a power of 2.
---
vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index e127e75..ef6bc3b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -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;
--
2.1.0
More information about the Android
mailing list