Android 中 Bitmap 和 Drawable 相互转换的方法
来源:互联网 发布:和msqrd差不多的软件 编辑:程序博客网 时间:2024/05/22 02:04
Drawable —> Bitmap
- 获取资源文件(Drawable)中的 Bitmap
Resources res = getResources();Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.ic_logo);
或者
Resource res = gerResource();Drawable drawable = res.getDrawable(id);//获取drawableBitmapDrawable bd = (BitmapDrawable) drawable;Bitmap bm = bd.getBitmap();
- 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; }
Bitmap —> Drawable
Drawable drawable = new BitmapDrawable(bmp);
Bitmap —> byte[]
public static byte[] getBytes(Bitmap bitmap){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); }
byte[] —> Bitmap
public static Bitmap Bytes2Bimap(byte[] b) { if (b.length != 0) { return BitmapFactory.decodeByteArray(b, 0, b.length); } else { return null; } }
1 2
- 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相互转换
- java布局 BoxLayout布局
- Android apk动态加载机制的研究
- ubuntu64位下安装的eclipse 出现双击代码闪退
- singleLine=”true” 和 maxLines=”1″的区别
- Qt窗口居中显示
- Android 中 Bitmap 和 Drawable 相互转换的方法
- 如何将pdf转换成ppt文件
- Android 5.0 InCallUI
- Android 颜色渲染(八) SweepGradient扫描/梯度渲染
- CSDN-markdown编辑器 快捷键
- Spring框架的基本概念
- Hexo-免费个人博客搭建框架使用
- Go计算运行的时间
- uva1423 拓扑排序