HTTP:HTTP GET Images

类别:Java 点击:0 评论:0 推荐:

......
DataInputStream iStrm = conn.openDataInputStream();
byte imageData[];

//如果已知图片尺寸
if (length != -1) {
    imageData = new byte[length];

    // 读取图片数据至imageData数组
    iStrm.readFully(imageData);

// 图片尺寸未知
} else {
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
    int ch;
    while ((ch = iStrm.read()) != -1)
        bStrm.write(ch);
    imageData = bStrm.toByteArray();
    bStrm.close();
}

//创建图片
image = Image.createImage(imageData, 0, imageData.length);
......

本文地址:http://com.8s8s.com/it/it15360.htm