一、安卓访问网络需要AndroidManifest.xml配置这样一个节点

<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获取图片信息的更多相关文章

  1. ios中从相册:相机中获取图片信息

    ios中从相册/相机中获取图片信息 从相册中获取图片的信息 UIImagePickerController *imgPickView = [[UIImagePickerController alloc ...

  2. #使用parser获取图片信息,输出Python官网发布的会议时间、名称和地点。

    # !/usr/bin/env/Python3 # - * - coding: utf-8 - * - from html.parser import HTMLParser import urllib ...

  3. js获取图片信息(一)-----获取图片的原始尺寸

    如何获取图片的原始尺寸大小? 如下,当给 img 设置一个固定的大小时,要怎样获取图片的原始尺寸呢? #oImg{ width: 100px; height: 100px; } <img src ...

  4. js获取图片信息(二)-----js获取img的height、width宽高值为0

    首先,创建一个图片对象: var oImg= new Image(); oImg.src = "apple.jpg"; 然后我们打印一下图片的信息: console.log(oIm ...

  5. GETorPOST方式保存和获取图片信息

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  6. C# 根据URL返回HTML_根据URL获取图片信息/缩略图

    /// <summary> /// 根据URL 返回HTML /// </summary> private List<string> GetHtmlByUrl(st ...

  7. 使用ExifInterface获取图片信息

    package com.example.readimage; import java.io.IOException; import android.media.ExifInterface; impor ...

  8. .net c#通过Exif获取图片信息(参数)

    简介 想要获取图片的信息,例如快门速度.ISO值等等,我们可以通过读取Exif中存储的信息.Exif(Exchangeable Image File)是存储在JPEG格式照片头部的一段信息,相机和手机 ...

  9. Android ImageView 获取图片信息后进行比较

    ImageView a=(ImageView)findViewById(R.id.imageView2); //获取当前图片ConstantState类对象 Drawable.ConstantStat ...

随机推荐

  1. ios 添加伪闪屏

    self.window.rootViewController.view.alpha = ; UIImageView *splashImageView = [[UIImageView alloc]ini ...

  2. SQL查询语句行转列横向显示

    http://blog.163.com/dreamman_yx/blog/static/26526894201121595846270/

  3. tp框架之数据添加

    1.数组添加 //$attr = array("Code"=>"n088","Name"=>"哈萨克族"); ...

  4. python计算文件的md5值

    前言 最近要开发一个基于python的合并文件夹/目录的程序,本来的想法是基于修改时间的比较,即判断文件有没有改变,比较两个文件的修改时间即可.这个想法在windows的pc端下测试没有问题. 但是当 ...

  5. winform公共标签和常用属性

    公共控件 1.Button(按钮): Enabled :确定是否启用控件 Visible:确定控件是否可见 2.CheckBox(多选项) CheckListBox -(多选项列表)可用CheckBo ...

  6. 浏览器-07 chromium 渲染1

    Chromium 软件渲染 软件渲染就是利用CPU,根据一定的算法来计算生成网页的内容; Chromium都是用软件渲染的技术来完成页面的绘制工作(除非强行打开硬件加速绘制); 软件渲染基础和架构 R ...

  7. asp.net c# 网上搜集面试题目大全(附答案)

    1.String str=new String("a")和String str = "a"有什么区别? String str = "a"; ...

  8. Difinition Of Done

    A Story is Sprint ready (Rally Defined) when............. The story has well defined and testable ac ...

  9. D3.js部署node环境开发

    总结一段D3.js部署node环境的安装过程 准备阶段: 首先电脑上要安装node环境,这个阶段过滤掉,如果node环境都不会装,那就别玩基于node环境搞的其他东西了. 搭建环境: 我在自己的F:系 ...

  10. Python for Infomatics 第12章 网络编程一(译)

    注:文章原文为Dr. Charles Severance 的 <Python for Informatics>.文中代码用3.4版改写,并在本机测试通过. 本书中的许多例子关注的是读取文件 ...