public byte[] getBitmapByte(Bitmap bitmap){
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return out.toByteArray();
} public Bitmap getBitmapFromByte(byte[] temp){
if(temp != null){
Bitmap bitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length);
return bitmap;
}else{
return null;
}
}
public static Bitmap drawableToBitmap(Drawable drawable){  

            int width = drawable.getIntrinsicWidth();  

            int height = drawable.getIntrinsicHeight();  

            Bitmap bitmap = Bitmap.createBitmap(width, height,  

                    drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888  

                            : Bitmap.Config.RGB_565);  

            Canvas canvas = new Canvas(bitmap);  

            drawable.setBounds(0,0,width,height);  

            drawable.draw(canvas);  

            return bitmap;  

        }  
Drawable drawable = new FastBitmapDrawable(bitmap);

Android中Bitmap、Drawable、byte[]转换的更多相关文章

  1. Android中Bitmap, Drawable, Byte,ID之间的转化

    Android中Bitmap, Drawable, Byte,ID之间的转化 1.  Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArray ...

  2. Android中Bitmap, Drawable, Byte之间的转化

    1.  Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap. ...

  3. Android中 Bitmap Drawable Paint的获取、转换以及使用

    比如Drawable中有一系列连续的图片,img_0.png, img_1.png, img_2.png ... 如果要动态获取这些图片,通过"R.drawable.img_x"的 ...

  4. Android Bitmap Drawable byte[] InputStream 相互转换方法

    用android处理图片的时候,由于得到的资源不一样,所以经常要在各种格式中相互转化,以下介绍了 Bitmap Drawable byte[] InputStream 之间的转换方法: import ...

  5. Android中的Drawable和动画

    Android中Drawable是一种可以在Canvas上进行绘制抽象的概念,种类很多,常见的颜色和图片都可以是一个Drawable.Drawable有很多种,它们表示一种图像的概念,但是它们又不全是 ...

  6. Android中各种Drawable总结

    在Android中,Drawable使用广泛,但是种类也多,基于<Android开发艺术探索>中对Drawable的讲解,总结了如下表格.

  7. android中Bitmap的放大和缩小的方法

    android中Bitmap的放大和缩小的方法 时间 2013-06-20 19:02:34  CSDN博客原文  http://blog.csdn.net/ada168855/article/det ...

  8. Android中Bitmap,byte[],Drawable相互转化

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

  9. 【Android】[转] Android中Bitmap,byte[],Drawable相互转化

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

随机推荐

  1. docker高级应用之cpu与内存资源限制(转)

    时间:2015-06-09 14:01:52      阅读:1581      评论:0      收藏:0      [点我收藏+] 标签:docker资源限制   docker cpu限制    ...

  2. 【微信小程序】转载:微信小程序实战篇-下拉刷新与加载更多

    下拉刷新 实现下拉刷新目前能想到的有两种方式 1. 调用系统的API,系统有提供下拉刷新的API接口 当然,你可以直接在全局变量app.json的window里面配置上面这个属性,这样整个项目都允许下 ...

  3. LaTeX 中使用三级标题

    需要在导言区加入命令:\setcounter{secnumdepth}{4} 而后: \section{一级标题} \subsection{二级标题} \subsubsection{三级标题}

  4. C#7.0之元组数据

    static (string,string,string) LookupName(int a) { return ("","",""); } ...

  5. js操作时间 加法 减法 计算 格式化时间

    Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...

  6. MongoDB Database Profiler

    数据库profiler细粒度收集mongodb的写操作.游标.数据库命令等.可以在数据库级别或者实例级别开启profiling. profiler将收集到的数据写入system.profile集合中. ...

  7. ubuntu设置自动休眠

    ubuntu16.04默认是永不休眠的,有时候忘了关机,那就惨了,一会用到没电为止. 设置方法: 进入“系统设置”->"安全与隐私"->"电源设置" ...

  8. Catalog的种类

    框架中的Catalog 在MEF框架中,包含了4种Catalog,所有的Catalog的是从System.ComponentModel.Composition.Primitives名称空间下的Comp ...

  9. Source Insight 项目简单使用说明

    SI(Source Insight) 是我一直写代码的好伙伴, 相信这强大的软件也是广大程序猿编写软件的利器. 正所谓" 工欲善其事, 必先利其器", 我们要学会利用这款软件. 先 ...

  10. 关于mysql内存表的一个帖子(转载)

    地址:http://bbs.csdn.net/topics/360030699 引用楼主 zgycsmb 的回复:问:1mysql的内存表性能怎么样2mysql的内存表与system v 这种共享内存 ...