如何在Android中使用Web服务显示图像 [英] How to display image in Android Using Web service

查看:92
本文介绍了如何在Android中使用Web服务显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找如何在数据库中存储图像并使用网络服务的解决方案我希望将该图像显示到Android应用程序

I am looking for the solution of how can i store image over internet in database and using web service i want to display that image into Android Application

推荐答案

你可以使用AsyncTask异步完成它。

You can use AsyncTask to get it done asynchronously.
private class FetchImageTask extends AsyncTask<String, Integer, Bitmap> {
    @Override
    protected Bitmap doInBackground(String... arg0) {
        Bitmap b = null;
        try {
            b = BitmapFactory.decodeStream((InputStream) new URL(arg0[0]).getContent());
        }
        catch (MalformedURLException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return b;
    }
}



使用它,


Use it as,

new FetchImageTask() {
        @Override
        protected void onPostExecute(Bitmap result) {
            if (result != null) {
                image.setImageBitmap(result);
            }
        }
    }.execute("IMAGE_URL");



参见here [ ^ ]



-KR


see here[^]

-KR


这篇关于如何在Android中使用Web服务显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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