Use Picasso to Place Image Into Drawable

☆樱花仙子☆ 提交于 2019-12-01 07:32:43
Ercan

There is something you miss about Picasso. You can set an annonymous Target class in inTo method like and set bitmap to any object you have :

Picasso.with(getBaseContext()).load("your url").into(new Target() {

                @Override
                public void onPrepareLoad(Drawable arg0) {


                }

                @Override
                public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
                    // TODO Create your drawable from bitmap and append where you like.

                }

                @Override
                public void onBitmapFailed(Drawable arg0) {


                }
            });

EDIT so this is how you do that:

public void appendToMessageHistory(String username, String message) {
        if (username != null && message != null) {

            ImageView image = new ImageView(getApplicationContext());

            Picasso.with(getBaseContext()).load("image url").into(new Target() {

                    @Override
                    public void onPrepareLoad(Drawable arg0) {


                    }

                    @Override
                    public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
                    Drawable drawImage = new BitmapDrawable(getBaseContext().getResources(),bitmap);
                     messageHistoryText.append(Html.fromHtml("<b>" + username + ":"
                    + "</b>" + "<br>"));
                    messageHistoryText.append(Html.fromHtml(message + "<hr>" + "<br>")
                    + System.getProperty("line.separator") + "");

                    messageHistoryText.append(Html.fromHtml("<img src = '"
                    + drawImage + "'/>",
                    imageGetter, null));    
                    }

                    @Override
                    public void onBitmapFailed(Drawable arg0) {


                    }
                });




        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!