首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

byte,drawable,bit地图图片相互转换

2012-10-28 
byte,drawable,bitmap图片相互转换private Drawable Bytes2Drawable(byte[] b) {if (b.length ! 0) {Bitm

byte,drawable,bitmap图片相互转换
private Drawable Bytes2Drawable(byte[] b) {
if (b.length != 0) {
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
Drawable drawable = new BitmapDrawable(bitmap);
return drawable;
} else {
return null;
}
}


private byte[] drawableToByte(int position){
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
mThumbIds[position]);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}


private byte[] bitmapToByte(Bitmap bm) {
Bitmap bmp = bm;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 30, baos);
return baos.toByteArray();
}

热点排行