星空网 > 软件开发 > 操作系统

android bitmap和数据流的互转

Bitmap aa = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
InputStream input = datastream(aa);//把bitmap转换为流
Bitmap bitmap = transformation(input);//把流转换为bitmap

public InputStream datastream (Bitmap bm){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
ByteArrayInputStream is = new ByteArrayInputStream(stream.toByteArray());
return is;
}

public Bitmap transformation(InputStream input){
if(input != null){
int len =-1;
byte[] temp = new byte[4 * 1024];
ByteArrayBuffer buffer = new ByteArrayBuffer(2 * 1024 * 1024);
try {
while ((len = input.read(temp)) != -1) {
buffer.append(temp,0,len);
}
Bitmap bmp = BitmapFactory.decodeByteArray(buffer.buffer(), 0, buffer.length());//把流转换为bitmap
} catch (IOException e) {
e.printStackTrace();
}
}
return bmp;
}




原标题:android bitmap和数据流的互转

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

跨境物流渠道有哪些:https://www.goluckyvip.com/tag/93310.html
跨境物流的主要模式有哪些:https://www.goluckyvip.com/tag/93313.html
跨境物流专线有哪些:https://www.goluckyvip.com/tag/93314.html
跨境专线物流有哪些:https://www.goluckyvip.com/tag/93315.html
跨境电子商务物流有哪些:https://www.goluckyvip.com/tag/93316.html
跨境物流商有哪些:https://www.goluckyvip.com/tag/93317.html
南京到普陀风景区 南京到普陀风景区怎么走:https://www.vstour.cn/a/404228.html
十堰有哪些官方网站:https://www.vstour.cn/a/404229.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流