http获取图片信息
2015-03-19 14:35
183 查看
一、安卓访问网络需要AndroidManifest.xml配置这样一个节点
<manifest>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
二、获取图片两种方法
第一种:
第二种方法:
<manifest>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
二、获取图片两种方法
第一种:
public Bitmap loadImageFromUrl(String url) throws Exception { final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet getRequest = new HttpGet(url); HttpResponse response = client.execute(getRequest); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.e("PicShow", "Request URL failed, error code =" + statusCode); } HttpEntity entity = response.getEntity(); if (entity == null) { Log.e("PicShow", "HttpEntity is null"); } InputStream is = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { is = entity.getContent(); byte[] buf = new byte[1024]; int readBytes = -1; while ((readBytes = is.read(buf)) != -1) { baos.write(buf, 0, readBytes); } } finally { if (baos != null) { baos.close(); } if (is != null) { is.close(); } } byte[] imageArray = baos.toByteArray(); return BitmapFactory.decodeByteArray(imageArray, 0, imageArray.length); }
第二种方法:
public byte[] getImage(String path) throws Exception { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("GET"); InputStream inStream = conn.getInputStream(); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { return readStream(inStream); } return null; }
相关文章推荐
- http://photo-sync.herokuapp.com/photos获取图片信息
- 无废话Android之内容观察者ContentObserver、获取和保存系统的联系人信息、网络图片查看器、网络html查看器、使用异步框架Android-Async-Http(4)
- 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例
- [C#.Net]利用HttpRequest登录到某个网站,然后获取网站信息的程序示例
- 利用HttpRequest 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例
- C#图片处理之: 获取数码相片的EXIF信息(二)
- ndis hook开发日志(2)-获取网卡信息 - Kevins的天空 http://rootsec.tk - CSDNBlog
- HttpRequest获取网站信息的程序示例
- 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例
- 关于在网页上获取信息.idhttp
- JS 客户端验证文件类型,获取图片信息
- 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例 [原创]
- 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例
- 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例
- 获取句柄的详细信息:(原代码) http://blog.vckbase.com/bastet/archive/2005/03/31/4244.html
- 获取图片总数及第一个图片的相关信息
- 利用HttpRequest登录到某个网站,然后获取网站信息的程序示例
- [asp.net]利用HttpRequest登录到某个网站,然后获取网站信息
- 通过HttpWebResponse和HttpWebRequest 获取http地址上的图片
- HttpRequest获取网站信息的程序示例