首先使用Picasso将图像加载到位图

Sha*_*yar 3 android bitmap picasso

我正在使用毕加索.我想先将图像添加到位图,然后将其添加到imageview.我正在使用以下代码行,使用uri从库中添加图像并在图像视图中显示它.我想先将它保存在位图上.我该怎么办:

Picasso.with(this).load(uriadress).into(imageView);
Run Code Online (Sandbox Code Playgroud)

但我想先将它保存在位图上.

nsh*_*ura 11

毕加索持有Target弱参考的实例.
因此最好保留Target为实例字段.
请参阅:https: //stackoverflow.com/a/29274669/5183999

private Target mTarget;

void loadImage(Context context, String url) {

    final ImageView imageView = (ImageView) findViewById(R.id.image);

    mTarget = new Target() {
        @Override
        public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){
            //Do something
            ...

            imageView.setImageBitmap(bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    };

    Picasso.with(context)
            .load(url)
            .into(mTarget);
}
Run Code Online (Sandbox Code Playgroud)