square / picasso

A powerful image downloading and caching library for Android
https://square.github.io/picasso/
Apache License 2.0
18.71k stars 3.97k forks source link

Picasso doesn't Rendered image on first call #1646

Open Odinilson opened 7 years ago

Odinilson commented 7 years ago

Hello, I'm trying to draw some images using canvas

I'm having problems since the images are not being rendered the first call I make an intent activity

I've seen some examples, which spoke about weak reference, I tried one of these solutions, but it still is not working.

*I'm sorry for my English, I'm still learning.

protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
         for (cells cell : cells){
               loadImage(R.id.image1,cell,canvas);
    }
}

private List<Target> garbageCollectorProtect = new LinkedList<>();

public void loadImage(int id, final Canvas canvas, Cell cell){

        Target target = new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {

        LogHelper.show(this,"Draw Bitmap...");

                Rect rectangle = new Rect(cell.getX(), cell.getY(),cell.getX()+(width),cell.getY()+(height));

        canvas.drawBitmap(bitmap, null, rectangle, null);

                garbageCollectorProtect.remove(this);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
                garbageCollectorProtect.remove(this);
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {

            }
        };
        garbageCollectorProtect.add(target);
        Picasso.with(getContext()).load(id).centerInside().resize(width,height).into(target);
}

Log Output Draw Bitmap ... 0 <- does not render Draw Bitmap ... 1 <- normal Draw Bitmap ... 2 <- normal

SupertigerDev commented 4 years ago

Same here. First time, onPrepareLoad gets a called only and nothing happens. the next try, it works fine