机器人:web服务图像替换与本地文件夹的图像 [英] android: webservice image replace with images in Local folder

查看:111
本文介绍了机器人:web服务图像替换与本地文件夹的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到android的聊天应用程序的最后阶段。

I am into final stage of chat application in android.

我现在面临几个问题,同时图像和Web服务的工作。

I am facing few issues while working with images and web service.

所以,当我选择图像,发送的图像Web服务我从服务URL。我怎么可以转换网址形象,是在我的本地文件夹中。我很困惑,我怎样才能使这个工作。

So when i select the image and sent that image to web service i get URL from service. How can i convert that url into image that is in my local folder. I am confused how can i make this working.

我想与来自Web服务返回的消息显示在列表视图中选定的图像。

I want to display the selected image in list view along with message returned from web service.

请指导我这个问题。是否有另一种选项来解决这个问题。

Please guide me in this issue. Is there another option to work this issue.

感谢。

推荐答案

使用此方法:

public static Bitmap getBitmapFromURL(String src) {
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url
            .openConnection();
            connection.setDoInput(true);
            connection.connect();
            connection.setReadTimeout(120000);
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

在这里,您需要将图像的URL传递给函数,你可以设置图片为setImageBitmap功能。

Here You need to pass the URL of the image to the function and you can set the image as setImageBitmap function.

这篇关于机器人:web服务图像替换与本地文件夹的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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