Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load Bitmap with RGB_565 via Picasso

is there a way to pass either a bitmap-config or force this BitmapConfig? I would like to not do it via Transformation() as this would consume more CPU than needed and I am not sure if this is done before the cache ( my main reason to do this is that the images in the cache should not consume that much memory )

like image 317
ligi Avatar asked May 21 '14 13:05

ligi


2 Answers

I found the solution - picasso 2.2.0 has now an API for this - was using 2.1.1 before and there was no API for this. Looks like this then:

picasso.load(url).config(Bitmap.Config.RGB_565).into(target);
like image 71
ligi Avatar answered Nov 06 '22 14:11

ligi


I have found a nice solution, that works very fine and 100%
(Sorry but answer of @ligi not works for me])
Use this util class for any picasso bitmap changes (here is RGB565)
Note also that Picasso build singleton class
So this only changes will cover all others (also if you don't plan to use RGB565 everywhere)

import com.squareup.picasso.Transformation;

public class Config565Transformation implements Transformation {

    @Override
    public Bitmap transform(Bitmap source) {
        Bitmap resultBitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(resultBitmap);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        canvas.drawBitmap(source, 0, 0, paint);
        source.recycle();
        return resultBitmap;
    }

    @Override
    public String key() {
        return Config565Transformation.class.getSimpleName();
    }
}

and simply use it

Picasso.with(getContext())
    .load(url)
    .transform(new Config565Transformation())
    .into(imageView);

Reference: https://habrahabr.ru/post/218453/

like image 1
Vlad Avatar answered Nov 06 '22 14:11

Vlad