Android中 Bitmap和Drawable相互转换的方法
来源:互联网 发布:软件定制开发公司名录 编辑:程序博客网 时间:2024/06/04 23:33
Drawable drawable =new BitmapDrawable(bmp);
3、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;
}
4、从资源中获取Bitmap
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);
5、Bitmap → byte[]
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray(); }
6、 byte[] → Bitmap
private Bitmap Bytes2Bimap(byte[] b){
if(b.length!=0){
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
else {
return null;
}
}
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android 中 Bitmap 和 Drawable 相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- Android Bitmap和Drawable相互转换方法
- Android Bitmap和Drawable相互转换方法
- android:Bitmap和Drawable相互转换方法
- android:Bitmap和Drawable相互转换方法
- Android:Bitmap和Drawable相互转换方法
- android:Bitmap和Drawable相互转换方法
- Android中Bitmap和Drawable相互转换
- Cordova和React-Native两种框架的对比
- Vue从入门到精通(7)--第四阶段(下):进阶
- 314. Binary Tree Vertical Order Traversal
- Linux grub.conf文件丢失/错误处理办法
- 源码分析mycat1.6之mysql通信协议篇之存储过程调用
- Android中 Bitmap和Drawable相互转换的方法
- css3弹性方块布局:Flex
- office web app实现文档的预览编辑
- 《程序员的自我修养--链接、装载与库》第一章阅读笔记
- 虚拟机扩充硬盘
- visibility:collapse;在table里面应用效果
- 2013年第四届蓝桥杯C/C++ C组决赛真题题解
- SQuirrel连接hive配置
- c语言求圆的周长和面积