使用毕加索得到一个回调位图毕加索、位图、回调

2023-09-12 07:48:04 作者:{甛玐寳

我使用毕加索图像下载我的应用程序。我在一个情况下,我需要先访问该位图前,它加载到ImageView的。在Downloader.Response类的presence似乎在暗示这是可能的,但我找不到任何用途的例子。我不想写一堆更code以异步方式处理这一特殊情况下,如果有可能做的毕加索。谁能告诉我该怎么办呢?

I'm using Picasso to download images for my app. I'm in a situation where I need to access the Bitmap first before it's loaded into the ImageView. The presence of the Downloader.Response class seems to suggest this is possible, but I can't find any use examples. I don't want to write a bunch more code to asynchronously handle this one particular case if it's possible to do with Picasso. Can anyone show me how to do it?

推荐答案

万一有人找到了答案,在github上很纳闷:

Found the answer on github in case anyone is wondering:

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

private void someMethod() {
   Picasso.with(this).load("url").into(target);
}

@Override 
public void onDestroy() {  // could be in onPause or onStop
   Picasso.with(this).cancelRequest(target);
   super.onDestroy();
}

建议不要使用匿名回调,并用一个实例变量为目标,而不是一职。

The post recommends not using an anonymous callback, and instead using an instance variable for target.