相关疑难解决方法(0)

519
推荐指数
15
解决办法
52万
查看次数

如何在android中显示来自url的图像

我查看了互联网,但未能找到如何从网址显示图像的工作示例.

以下代码崩溃,我无法找到原因..非常感谢任何帮助.谢谢.

TesteImages.java:

package pac.image3;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class TestImages extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.test_image);

        String imageUrl = "http://www.small-world.net/_borders/small_world_logo.gif";
        try {
          ImageView i = (ImageView)findViewById(R.id.test_image);
          Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
          i.setImageBitmap(bitmap);
          setContentView(image);
        } catch (MalformedURLException e) {
          e.printStackTrace();
        } catch (IOException …
Run Code Online (Sandbox Code Playgroud)

android imageview

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

imageview ×2

bitmap ×1