Load the image with Picasso to a bitmap first

综合技术 2017-11-13 阅读原文

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 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);
}
Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!

您可能感兴趣的

Android的启动模式 我们都知道,开启一个Activity,系统会在任务栈中创建实例,而任务栈是一种“后进先出”的栈结构。默认情况下,开启一个Activity,系统会创建实例,如果多...
Android-性能优化-UI优化 概述 Android 应用的卡顿,丢帧等,这些影响用户体验的因素绝大部分都与 16ms 这个值有关。 下面我们来讨论下 UI 渲染方面影响应用流畅性的因素。...
Android 6.0(API 23) 运行时权限(二)之权限申请... Android M 在上一篇中简单介绍了运行时权限,今天就讲讲怎么去申请权限。这个项目中本来用了一个第三方的权限框架,但是不太好用,我就在g...
Add Lock Screen Widgets on Android Nougat with an ... Ever since we announced the arrival of official Xposed Framework for Nougat ear...