从网址下载的图片未显示在视图中

时间:2011-09-16 10:29:05

标签: android

我想问我从url下载图像意味着我在字符串数组中有url并且在按钮上单击我移动到下一个url并从服务器下载图像。 它完美地运行在三星galaxy s2手机和图像下载和显示在视图中,但在一些其他小尺寸屏幕的移动它不在视图中显示,但在一些它显示...这是什么发生背后的原因..i在onpostExecute()中使用setimageBitmap(),它适用于三星galaxys2低范围移动为什么它不显示..i也改变图像视图高度和宽度但不解决..但有一段时间显示..

我的代码在下面..

log cat:

  logcat out  put :



   DEBUG/skia(231): --- decoder->decode returned false
  INFO/System.out(231): Bitmap :: null
  INFO/System.out(231): Bitmap on post :: null
 WARN/InputManagerService(63): Window already focused, ignoring focus gain of:   com.android.internal.view.IInputMethodClient$Stub$Proxy@44c17828
INFO/System.out(231): Message sent
 INFO/image url/////(231):   http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/agenda/exposiciones_muestras/carlos_cruz-diez/carlos_cruz-diez2/507989-1-esl-AR/Carlos_Cruz-Diez.jpg
   INFO/System.out(231): Bitmap :: android.graphics.Bitmap@44d64750
     INFO/System.out(231): Bitmap on post :: android.graphics.Bitmap@44d64750

3 个答案:

答案 0 :(得分:1)

尝试这个来获取Image ::

 ImageButton   tran_btn_skip = (ImageButton) findViewById(R.id.tran_btn_skip);

        try {
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                    "http://www.hermann-uwe.de/files/images/blue_flower.preview_0.jpg")
                    .getContent());
            tran_btn_skip.setImageBitmap(bitmap);
        } catch (Exception e) {
        }

显示权限:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

如果从服务器加载,请在移动设备(not in emulator)中尝试此操作但是,如果从任何其他服务器加载10,则可以在模拟器中显示。

更新::

see

package com.progressbar;

import java.io.InputStream;
import java.net.URL;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageButton;
public class progressbar extends Activity  {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageButton   tran_btn_skip = (ImageButton) findViewById(R.id.login);

        try {
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                    "http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/agenda/exposiciones_muestras/leila_tschopp3/baja-leila_tschopp_-_river_-acrilico_sobre_tela-130x150_cm_-_2011/498599-1-esl-AR/BAJA-Leila_Tschopp_-_River_-acrilico_sobre_tela-130x150_cm_-_2011.jpg")
                    .getContent());
            tran_btn_skip.setImageBitmap(bitmap);
        } catch (Exception e) {
        }

    }
    }

答案 1 :(得分:0)

试试这个:

   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
   conn.setDoInput(true);
   conn.setConnectTimeout(7000);
   conn.connect();
   BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
   Drawable drawable = Drawable.createFromStream(is, imageUrl);
   view.setImageBitmap(drawable)

答案 2 :(得分:0)

以下是完整的代码:

String imageUrl = "http://someurl.com/example.png";
URL url = new URL(imageUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(7000);
conn.connect();
BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
Drawable imageDrawable = Drawable.createFromStream(is, imageUrl);
view.setImageBitmap(imageDrawable);