Open Odinilson opened 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
Same here. First time, onPrepareLoad gets a called only and nothing happens. the next try, it works fine
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.
Log Output Draw Bitmap ... 0 <- does not render Draw Bitmap ... 1 <- normal Draw Bitmap ... 2 <- normal