目的是取本来或者网络图片,将之转换成Bitmap, 再显示到相应的容器中..

1.设置缓冲区大小

private static final int IO_BUFFER_SIZE = 4 * 1024;

2.自写的函数public static Bitmap GetNetBitmap(String url):

public static Bitmap GetNetBitmap(String url) {
        Bitmap bitmap = null;
        InputStream in = null;
        BufferedOutputStream out = null;
        try {
            in = new BufferedInputStream(new URL(url).openStream(),
                    IO_BUFFER_SIZE);
            final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
            out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
            copy(in, out);
            out.flush();

            byte[] data = dataStream.toByteArray();
            bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
            data = null;
            return bitmap;
        } catch (IOException e) {

            e.printStackTrace();
            return null;
        }
    }

3.附加的copy函数

private static void copy(InputStream in, OutputStream out)
            throws IOException {
        byte[] b = new byte[IO_BUFFER_SIZE];
        int read;
        while ((read = in.read(b)) != -1) {
            out.write(b, 0, read);
        }
    }

4.GetNetBitmap()函数参数说明:

url – 网络或者本地图片的绝对路径,比如:

A.网络路径: url=”http://blog.foreverlove.us/girl2.png”  ;

B.本地路径:url=”file://mnt/sdcard/photo/image.png”;

C.支持的图片格式 ,png, jpg,bmp,gif等等