0

谁能告诉我如何使用来自网络服务的图像,并告诉我如何将这些图像显示到 android 的 imageview 控件中?

我通过谷歌尝试了很多例子,但这些都没有让我清楚。

谁能给我至少一个样品来实现这个概念?

感谢您宝贵的时间!...

4

6 回答 6

0

您可以使用存储在服务器中的图像的 url 来使用来自网络服务器的图像....

于 2013-03-18T07:32:26.417 回答
0

您使用的是什么类型的网络服务?

如果您使用的是 KSOAP,您可以像这样使用。

          try 
           {

                ht.call(SOAP_ACTION, envelope);

                final SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

              final String encodedImage = response.toString();

      byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);

      decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

      yourimgView.setImageBitmap(decodedByte);

            catch (Exception e) {
            e.printStackTrace();
        }
于 2013-03-18T07:35:13.850 回答
0

android默认ImgaeView不支持http URI ..您可以使用支持http URI作为图像url的第三方库RemoteImagView....

于 2013-03-18T07:38:08.040 回答
0

从 API 获取 Image_URL:

例如: http: //lh6.googleusercontent.com/-jZgveEqb6pg/T3R4kXScycI/AAAAAAAAAE0/xQ7CvpfXDzc/s1024/sample_image_01.jpg

将此 URL 传递给以下函数,您将获得一个 Bitmap :

public static Bitmap loadBitmap(String url) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;

try {
    in = new BufferedInputStream(new URL(url).openStream(), IO_BUFFER_SIZE);

    final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
    copy(in, out);
    out.flush();

    final byte[] data = dataStream.toByteArray();
    BitmapFactory.Options options = new BitmapFactory.Options();
    //options.inSampleSize = 1;

    bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
} catch (IOException e) {
    Log.e(TAG, "Could not load Bitmap from: " + url);
} finally {
    closeStream(in);
    closeStream(out);
}

return bitmap;

}

你可以设置 image.setImageBitmap(bitmap);

希望这可以帮到你。

注意:如果要加载图像列表,请使用惰性加载器。

于 2013-03-18T07:39:35.350 回答
0

检查您的网络服务的响应,在那里您可以找到图像 URL,获取该 url 并将其传递给图像视图对象。如果您发布您的网络服务响应,您将得到您问题的正确响应。

于 2013-03-18T07:39:48.477 回答
0

无论使用什么 webserverice,soap 或 json 您都必须获取 url。

ImageView imageView = (ImageView) findViewById(R.id.detailImageView);

if(urlToDownload!=null)
{
URL url = new URL(urlToDownload);//url of image to download.
url.openConnection().setConnectTimeout(1000);
bitmap =BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bitmap);
}
于 2013-03-18T07:43:22.337 回答