Drawable、Bitmap和byte[]之间的转换
来源:互联网 发布:软件开发程序文件 编辑:程序博客网 时间:2024/05/18 06:35
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;
- }
- }
- Drawable、Bitmap和byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换 (转)
- Drawable、Bitmap、byte[]之间的转换 (转)
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换
- Drawable、Bitmap、byte[]之间的转换问题
- Drawable, Bitmap, byte[]之间的转换
- sql server数据库存储image类型的一种方法
- Android 手机震动节奏
- 考研之计算机学习笔记序列之栈的结构实现
- 获取系统版本
- logic:forward标签跳转问题
- Drawable、Bitmap和byte[]之间的转换
- android 定制Dialog (一)
- Android EditText插入字符串到光标所在位置和删除
- OPhone 自定义输入法教程
- java,c,c++ 之间基本数据类型的比较和理解
- 水温控制系统
- Google Android Market电子市场/应用商店
- 推荐10个Android开源项目
- java map