您的位置:首页 > 其它

从网上读取图片在本地显示

2013-04-27 00:18 507 查看
转载自:http://www.eoeandroid.com/thread-26-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
【eoeAndroid社区】现在大部分的android手机应用,主要都是用HTTP协议来进行网络通讯,利用post方式来传递JSON或者XML等报文数据,比如现在很多的services远程服务调用都是用这种方式。间或有一些应用会用Socket方式进行数据传递,或者利用它的长连接等属性来做一些特殊的服务,或者涉及到自定义的报文格式以及编码解码的格式等等。本索旨在将此范围内的论坛资源分类整理,方便开发者查找学习。

1、【eoeAndroid社区索引】android网络通信之HTTP协议教程实例汇总

http://www.eoeandroid.com/thread-167916-1-1.html

2、【eoeAndroid社区索引】android网络通信之Email教程实例汇总

http://www.eoeandroid.com/thread-168160-1-1.html

3、【eoeAndroid社区索引】android网络通信之socket教程实例汇总]

http://www.eoeandroid.com/thread-168313-1-1.html

4、【eoeAndroid社区索引】android网络通信之WIFI教程实例汇总

http://www.eoeandroid.com/thread-168706-1-1.html

5、【eoeAndroid社区索引】android网络通信之蓝牙教程实例汇总

http://www.eoeandroid.com/thread-168948-1-1.html

学好android开发并不难,eoeAndroid社区为大家来助力,我们为大家汇总的帖子如果有不全的地方,欢迎广大的网友来补充更新我们的汇总帖子,大家可以在本帖中跟帖补充相关知识点,也可以加管理员QQ:1225408768,领取一个大类,进行常规的更新来为社区做出自己的贡献。

===其他14大类android开发知识汇总主帖推荐===:

1. 【eoeAndroid社区索引】android开发环境搭建详尽教程实例

2. 【eoeandroid社区】android 开发基础汇总主帖

3. 【eoeAndroid社区】android
GPS索引汇总主帖

4. 【eoeAndroid社区】android用户界面索引汇总主帖

5. 【eoeAndroid社区】android数据存储索引汇总主帖

6. 【eoeAndroid社区】android
Activity索引汇总主帖

7. 【eoeAndroid社区】android多媒体索引汇总主帖

8. 【eoeAndroid社区】android图形图像索引汇总主

9. 【eoeAndroid社区】android高级篇索引汇总主帖

10.【eoeAndroid社区】android游戏开发索引汇总主帖

11.【eoeAndroid社区】android设备功能索引汇总主帖

12.【eoeAndroid社区】android
第三方集成索引汇总主帖

13.【eoeAndroid社区】android
源码开发索引汇总主帖

14.【eoeAndroid社区索引】android之ROM教程实例汇总

跟我一起念:公(gong)钥(yue)

Android高级篇之加密解密

一、实例教程

Android 加密解密

http://www.eoeandroid.com/thread-66236-1-1.html

Android 加密解密字符串

http://www.eoeandroid.com/thread-81425-1-1.html

Android 用MD5加密算法加密密码(一)

http://www.eoeandroid.com/thread-97843-1-1.html

Android 用MD6加密算法加密密码(二)

http://www.eoeandroid.com/thread-97846-1-1.html

鉴客 Android客户端与服务器端通过DES加密认证

http://www.eoeandroid.com/thread-159272-1-1.html

android下md5加密,大家收藏下吧 ,用到的时候可以直接拿来用

http://www.eoeandroid.com/thread-51590-1-1.html

Android 获取自己程序APK包的MD5指纹

http://www.eoeandroid.com/thread-92389-1-1.html

给自己的网络数据加密

http://www.eoeandroid.com/thread-97336-1-1.html

JAVA加密解密

http://www.eoeandroid.com/thread-69738-1-1.html

二、资料下载

加密记事本,陈年作品(源码放出)

http://www.eoeandroid.com/thread-99203-1-1.html

通用DES加密解密方法

http://www.eoeandroid.com/thread-56774-1-1.html

一个加密的记事本

http://www.eoeandroid.com/thread-122363-1-1.html

三、EOE社区实战问题解答

Android ZIP 加密解密

http://www.eoeandroid.com/thread-116230-1-1.html

android AES加密和解密

http://www.eoeandroid.com/thread-162137-1-1.html

关于android加密

http://www.eoeandroid.com/thread-73308-1-1.html

android 与 java 的RSA加解密

http://www.eoeandroid.com/thread-72268-1-1.html

求高手相助,关于Android加密的问题

http://www.eoeandroid.com/thread-63822-1-1.html

Android下DES加密和J2SE平台下加密结果不一样

http://www.eoeandroid.com/thread-83595-1-1.html

Android中自带的RSA加密算法和JAVA中的不是一个标准的吗?

http://www.eoeandroid.com/thread-102614-1-1.html

在DES解密时候出现pad block corrupted错误

http://www.eoeandroid.com/thread-63284-1-1.html

请问一下,android与PHP连接安全问题

http://www.eoeandroid.com/thread-73501-1-1.html

短信加密问题

http://www.eoeandroid.com/thread-75590-1-1.html

我java des加密后的密文和c加密出来的最后一段密文不一样!

http://www.eoeandroid.com/thread-57876-1-1.html

MD5 加密的方法不能理解

http://www.eoeandroid.com/thread-69619-1-1.html

全新的数据加密技术

http://www.eoeandroid.com/thread-69548-1-1.html

求:文件/文件夹加密 解决方案 或指点

http://www.eoeandroid.com/thread-114552-1-1.html

CRC32算法如何加密字符串?

http://www.eoeandroid.com/thread-102782-1-1.html

讨论一下 :文件/文件夹 的加密和解密 如何实现

http://www.eoeandroid.com/thread-114550-1-1.html

关于程序加密的问题

http://www.eoeandroid.com/thread-91900-1-1.html

请教Android上的DSA加密方法

http://www.eoeandroid.com/thread-63756-1-1.html

Json在android中的加密传输

http://www.eoeandroid.com/thread-82508-1-1.html

怎么给视频加密?

http://www.eoeandroid.com/thread-101882-1-1.html

资源图片压缩或加密求助

http://www.eoeandroid.com/thread-71619-1-1.html

android客户端 访问服务器的url加密 求加密方式

http://www.eoeandroid.com/thread-147709-1-1.html

怎么实现对android的文件夹加密或者锁定啊?

http://www.eoeandroid.com/thread-24955-1-1.html

如何给文件加密?

http://www.eoeandroid.com/thread-68058-1-1.html

四、社区求助未解答帖

android 如何对视频加密和解密

http://www.eoeandroid.com/thread-103350-1-1.html

android base64加密 解码 apk信息读取问题请教

http://www.eoeandroid.com/thread-163307-1-1.html

android与PC socket传输加密密文出错

http://www.eoeandroid.com/thread-156109-1-1.html

android下是否能用classloader对class进行加解密

http://www.eoeandroid.com/thread-72582-1-1.html

新手请教各位大虾: 一个报错,详细请看里面

http://www.eoeandroid.com/thread-157399-1-1.html

开发/调试MD5指纹和生产/发布MD5指纹

http://www.eoeandroid.com/thread-65795-1-1.html

加密数据库查询的问题

http://www.eoeandroid.com/thread-166386-1-1.html

二维码加密了

http://www.eoeandroid.com/thread-172262-1-1.html

求一个能实现短信加密解密功能的源码!

http://www.eoeandroid.com/thread-161206-1-1.html

急求android短信加密图片加密的源码

http://www.eoeandroid.com/thread-166981-1-1.html

加密相片

http://www.eoeandroid.com/thread-66466-1-1.html

明文加密码 加密后密文长度不变 要怎么实现?

http://www.eoeandroid.com/thread-111009-1-1.html

加密记事本都用到了android哪些知识 希望能得到详细讲解

http://www.eoeandroid.com/thread-172381-1-1.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: