[Android] Do not rescale bitmap

Ludovic Fauvet etix at videolan.org
Tue Apr 7 16:48:32 CEST 2015


On Tue, Apr 7, 2015, at 10:45, Geoffrey Métais wrote:
> vlc-ports/android | branch: master | Geoffrey Métais
> <geoffrey.metais at gmail.com> | Thu Apr  2 16:36:56 2015 +0200|
> [139271d6da979dbf68a7af8ea3e5c0c907d8efd2] | committer: Geoffrey Métais
> 
> Do not rescale bitmap
> 
> It avoid to duplicate bitmap in memory.
> Thus, inSampleSize must be a power of 2.

Not sure it's a great idea. Did you try to load a bitmap with an
outrageously huge size?

> > http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=139271d6da979dbf68a7af8ea3e5c0c907d8efd2
> ---
> 
>  .../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;
> 
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android


-- 
Ludovic Fauvet
www.videolan.org


More information about the Android mailing list