Android中Bitmap、Drawable、byte[]转换
来源:互联网 发布:水果软件12教程 编辑:程序博客网 时间:2024/05/22 14:53
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[]之间的转换
- 碰到的word文档提示找不到package解决办法
- 体验新理财方式:余额宝与微信理财
- /bin/sh: autoreconf: command not found (centos 6.5 install qemu from source code)
- android:textAlignment 参数解释
- 文件I/O操作之open 的O_APPEND参数
- Android中Bitmap、Drawable、byte[]转换
- js正则表达式把不符合条件的字符替换处理(总结)
- 教你使用阿里云服务器挂载数据盘
- CVS
- spring mvc框架下controller中如何读取properties文件内容
- uva----10905
- Android应用卸载器
- 九度OJ 1084: 整数拆分
- CSS入门之文本样式用法(文本对齐,首行缩进,文本竖排,文字方向)