首先将Picasso的图像加载到位图 [英] Load Image With Picasso to a bitmap first

查看:95
本文介绍了首先将Picasso的图像加载到位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Picasso. And i want to add the image to bitmap first and then add it to an imageview. I'm using the following line of code that adds an image from gallery with uri and show it on image view. I want to save it on a bitmap first. what should i do:

Picasso.with(this).load(uriadress).into(imageView);

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

but i want to save it on a bitmap first.

推荐答案

Picasso持有Target具有弱引用的实例.
因此最好将Target保留为实例字段.
参见: https://stackoverflow.com/a/29274669/5183999

Picasso holds Target instance with weak reference.
So it is better to hold Target as instance field.
see: 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);
}

这篇关于首先将Picasso的图像加载到位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆