Bitmap和Drawable的互相转换
刚好之前的项目实用到。怕遗忘了。就先记录下来。然后会用到的时候直接来这copy使用就好了。
1.Bitmap ---->Drawable:
public static Drawable bitmapToDrawable(Bitmap bitmap) {
BitmapDrawable bd = new BitmapDrawable(bitmap);
return bd;
}
2.Drawable---->Bitmap:
public static Bitmap drawableToBitmap(Drawable drawable) {
// 取 drawable 的长宽
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}
That is Over。
Bitmap和Drawable的互相转换的更多相关文章
- Android图片二进制与Bitmap、Drawable之间的转换
Android图片二进制与Bitmap.Drawable之间的转换 Java代码 public byte[] getBitmapByte(Bitmap bitmap){ ByteArray ...
- Android中Bitmap、Drawable、byte[]转换
public byte[] getBitmapByte(Bitmap bitmap){ ByteArrayOutputStream out = new ByteArrayOutputStream(); ...
- Drawable、Bitmap、byte[]之间的转换
android在处理一写图片资源的时候,会进行一些类型的转换: 1 Drawable → Bitmap 的简单方法 ((BitmapDrawable)res.getDrawable(R.drawabl ...
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】
package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; ...
- Android Drawable、Bitmap、byte[]之间的转换
转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...
- Android 图片Bitmap,drawable,res资源图片之间转换
一.知识介绍 ①res资源图片是放在项目res文件下的资源图片 ②BitMap位图,一般文件后缀为BMP,需要编码器编码,如RGB565,RGB8888等.一种逐像素的显示对象,其执行效率高,但缺点也 ...
- Android中Bitmap,byte[],Drawable相互转化
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- 【Android】[转] Android中Bitmap,byte[],Drawable相互转化
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- Android中Bitmap和Drawable
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
随机推荐
- 并发系列6-Java并发面试系列文章总结【石杉的架构笔记】
- 洛谷——P1104 生日
P1104 生日 题目描述 cjf君想调查学校OI组每个同学的生日,并按照从大到小的顺序排序.但cjf君最近作业很多,没有时间,所以请你帮她排序. 输入输出格式 输入格式: 有2行, 第1行为OI组总 ...
- ALL运算符
ALL在英文中的意思是“所有”,ALL运算符要求比较的值需要匹配子查询中的所有值.ALL运算符同样不能单独使用,必须和比较运算符共同使用. 下面的SQL语句用来检索在所有会员入会之前出版的图书: SE ...
- Python开发基础-Day22反射、面向对象进阶
isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象,如果是返回True class Foo ...
- coreseek 段错误 (core dumped) 问题
coreseek建立索引出现上面问题经过测试发现有下面几个原因: 1. 分词配置文件不存在 uni.lib 2. uni.lib配置文件格式不正确
- UML对象图、包图
对象图(Object Diagram)显示了一组对象和他们之间的关系.使用对象图阿狸说明数据结构,类图中的类或组件等实例的快照.对象图和类图一样,反应了系统的静态过程,但它是以实际的或原型化为基础来表 ...
- [POJ1980]Unit Fraction Partition(搜索)
Unit Fraction Partition Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4571 Accepted ...
- Codeforces Gym 100269K Kids in a Friendly Class 构造题
Kids in a Friendly Class 题目连接: http://codeforces.com/gym/100269/attachments Description Kevin resemb ...
- 用WPF写了一个弹幕播放器
看弹幕视频的时候,如果不发弹幕,一个本地的弹幕播放器往往能带来更好的体验.目前已经有一些实现了,最初用过一个MukioPlayer, 后来又用过一个用C++写的BiliLocal,这个程序能自动下载弹 ...
- 汇编语言---GCC内联汇编
转:http://www.cnblogs.com/taek/archive/2012/02/05/2338838.html GCC支持在C/C++代码中嵌入汇编代码,这些代码被称作是"GCC ...