从网上读取图片在本地显示
2013-04-27 00:18
507 查看
转载自:http://www.eoeandroid.com/thread-26-1-1.html
从网上读取图片在本地显示:
layout下配置文件goimg.xml
注意,想要让你的程序可以访问网络,你必须在menifest文件里边增加:
http://www.eoeandroid.com/thread-172943-1-1.html
从网上读取图片在本地显示:
package df.util; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.widget.Button; import android.widget.ImageView; import com.aspire.demo.R; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; /** * Created with IntelliJ IDEA. * User: pdh * Date: 13-4-26 * Time: 下午11:46 * To change this template use File | Settings | File Templates. */ public class ActivityMain extends Activity { /** Called when the activity is first created. */ String imageUrl = "http://www.huway.com/d/file/2011/03/02/689803e7955dd20ab84d91ed409761d3.jpg"; Bitmap bmImg; ImageView imView; Button button1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.goimg); imView = (ImageView) findViewById(R.id.imview); imView.setImageBitmap(returnBitMap(imageUrl)); } public Bitmap returnBitMap(String url) { URL myFileUrl = null; Bitmap bitmap = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl .openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } }
layout下配置文件goimg.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/imview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> </LinearLayout>
注意,想要让你的程序可以访问网络,你必须在menifest文件里边增加:
<uses-permission android:name="android.permission.INTERNET" />
http://www.eoeandroid.com/thread-172943-1-1.html
相关文章推荐
- FileReader:读取本地图片文件并显示
- SpringMVC读取本地图片(byte[]流方式)显示到前端页面
- input file文件上传(multiple)及FileReader:读取本地图片文件并显示
- springmvc读取本地图片并显示
- 读取input:file的路径并显示本地的图片
- 【Android】用ImageView显示本地和网上的图片
- FileReader:读取本地图片文件并显示
- 读取本地图片显示在JSP页面上
- Android用ImageView显示本地和网上的图片
- java读取本地图片并在网页显示
- Servlet从本地文件中读取图片,并显示在页面中
- FileReader:读取本地图片文件并显示
- 读取input:file的路径并显示本地图片的方法
- spring mvc 从本地文件中读取图片,并显示在页面中
- 读取input:file的路径并显示本地图片的方法
- Android用ImageView显示本地和网上的图片
- SpringMVC从本地磁盘读取图片显示到JSP页面上
- FileReader:读取本地图片文件并显示
- 读取input:file的路径并显示本地图片的方法
- java 通过流的方式读取本地图片并显示在jsp 页面上(类型以jpg、png等结尾的图片)