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

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/99079.html
joom入驻资料:https://www.goluckyvip.com/tag/9908.html
印尼海运到中国:https://www.goluckyvip.com/tag/99080.html
海运印尼到中国:https://www.goluckyvip.com/tag/99081.html
越南中国海运:https://www.goluckyvip.com/tag/99082.html
日亚海运:https://www.goluckyvip.com/tag/99083.html
皇帝的皇宫=:https://www.vstour.cn/a/363188.html
海南岛琼海市旅游景点 琼海市的旅游景点:https://www.vstour.cn/a/363189.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流