Drawable,Bitmap,byte[]的相互转换
来源:互联网 发布:ppsspp源码 编辑:程序博客网 时间:2024/06/06 02:31
这是我从ITeye技术论坛上转来的,原址在这里:点击打开链接
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; } }
0 0
- Drawable、 Bitmap、byte[] 的相互转换
- Drawable,Bitmap,byte[]的相互转换
- Drawable、 Bitmap、byte[] 的相互转换
- Bitmap Byte 和Drawable 的相互转换
- Bitmap byte Drawable 相互转换
- android byte[]数组,bitmap,drawable之间的相互转换
- android 中byte[] bitmap drawable inputstream的相互转换
- Bitmap与byte、file、Drawable之间的相互转换
- BitMap,inputStream,byte[],Drawable之间的相互转换
- 【Android】Bitmap、InputStream、Drawable、byte[]、Base64之间的相互转换
- android Bitmap、Drawable、byte[]相互转换
- Android Bitmap Drawable byte[] InputStream 相互转换
- Bitmap和Drawable之间的相互转换、Bitmap和 byte[] 之间的相互转换、从资源中获取Bitmap
- Bitmap,Drawable,byte间的相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- Bitmap,byte[],Drawable相互转化
- gcc内嵌的汇编at&a汇编(初览)
- 我的电子商务之路(二)
- C++ 容器及选用总结
- 重装系统 遇到 windows无法安装到这个磁盘 GPT分区就转化为MBR
- 安装启动bluestacks
- Drawable,Bitmap,byte[]的相互转换
- GCC的内嵌汇编,也就是AT&T汇编语言语法
- Leetcode: Convert Sorted Array to Binary Search Tree
- 可安装多个系统的移动硬盘制作
- hibernate中配置文件的cascade的属性设置
- 我的2013——从早十点到晚十点的日子
- codeforces日记371e
- maven 压缩、合并 js, css
- std::tr1::function 示例(感谢大神)