Android中Bitmap、Drawable、byte[]转换
来源:互联网 发布:mac能用excel吗 编辑:程序博客网 时间:2024/05/01 21:29
1.Drawable—>Bitmap
Resources res=getResources();
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.sample_0);
2.Bitmap---->Drawable
Drawable drawable =new BitmapDrawable(bmp);
另外在网上搜了些,也不知到底谁是原创的
1、Drawable → Bitmap
public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
//canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
2、从资源中获取Bitmap
Resources res=getResources();
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);
3、Bitmap → byte[]
private byte[] Bitmap2Bytes(Bitmap bm){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray(); }
4、 byte[] → Bitmap
private Bitmap Bytes2Bimap(byte[] b){
if(b.length!=0){
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
else {
return null;
}
}
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换 (
- Android中Bitmap、Drawable、byte[]转换(hdp)
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Bitmap、Drawable、byte[]转换
- Android中Drawable、Bitmap、byte
- android 中byte[] bitmap drawable inputstream的相互转换
- Android中Bitmap, ID,Drawable, Byte之间的转换
- android Bitmap、Drawable、byte[]相互转换
- Android Drawable、Bitmap、byte[]之间的转换
- Android Drawable、Bitmap、byte[]之间的转换
- Android Drawable、Bitmap、byte[]之间的转换
- 什么是大数据?
- 林达华推荐的几本数学书
- Java POI的HelloWorld
- Android开发:在onTouchEvent中处理任意时间的长按事件
- 使用优先队列构建赫夫曼树
- Android中Bitmap、Drawable、byte[]转换
- 怎样培养独挡一面的能力
- 【翻译】在Ext JS 5应用程序中如何使用路由
- Welcome Docker to SUSE Linux Enterprise Server【水平有限,中英对照,求纠错】
- Eclipse Xtend - 疯狂的Java10
- Extjs window弹出框 第二次打开时会报:【'addCls' 为空或不是对象】错误
- 黑马程序员——学习日志1概述
- php-curl
- c++强制类型转换:dynamic_cast、const_cast 、static_cast、reinterpret_cast