首页 > 技术文章 > Android 接收服务器传来的图片踩过的坑

code666 2017-06-06 12:40 原文

byte[] data=SocketClientUtil.receiveData(bytes);            //,result
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, outPut);
iv_image.setImageBitmap(bmp);



ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while((len = in.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
Bitmap bmp = BitmapFactory.decodeByteArray(outputStream.toByteArray(), 0, outputStream.toByteArray().length);
//bmp.compress(Bitmap.CompressFormat.JPEG, 100, outPut);
iv_image.setImageBitmap(bmp);

推荐阅读