Drawable和Bitmap区别

Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565、RGB888。作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低。我们理解为一种存储对象比较好。
    Drawable - 作为Android平下通用的图形对象,它可以装载常用格式的图像,比如GIF、PNG、JPG,当然也支持BMP,当然还提供一些高级的可视化对象,比如渐变、图形等。

A bitmap is a Drawable. A Drawable is not necessarily a bitmap. Like all thumbs are fingers but not all fingers are thumbs.
Bitmap是Drawable . Drawable不一定是Bitmap .就像拇指是指头,但不是所有的指头都是拇指一样.

The API dictates: API规定:

Though usually not visible to the application, Drawables may take a variety of forms: 尽管通常情况下对于应用是不可见的,Drawables 可以采取很多形式:

Bitmap: the simplest Drawable, a PNG or JPEG image. Bitmap: 简单化的Drawable, PNG 或JPEG图像. 
Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.
Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.
Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
States: a compound drawable that selects one of a set of drawables based on its state.
Levels: a compound drawable that selects one of a set of drawables based on its level.
Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.

小结:

对比项          显示清晰度      占用内存     支持缩放    支持色相色差调整      支持旋转     支持透明色       绘制速度           支持像素操作

Bitmap          相同                大                 是                是                            是                是                     慢                      是
Drawable       相同                小                 是               否                            是                 是                     快                      否

Drawable在内存占用和绘制速度这两个非常关键的点上胜过Bitmap

1)Drawable和Bitmap之间可以互相转换。Drawable占用内存远小于Bitmap。
(2)setImageDrawable使用资源文件;setImageBitmap使用bitmap图片,该图片可能是读取本地相册,或者从资源文件转换而来。
(3) public void setImageResource (int resId)占用UI thread;

ImageView iv; 
String fileName = "/data/data/com.test/aa.png; 
Bitmap bm = BitmapFactory.decodeFile(fileName); 
iv.setImageBitmap(bm); //占用内存,ie:

Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(image);

Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
BitmapDrawable bitmapDrawable = new BitmapDrawable(image);
imageView.setImageDrawable(bitmapDrawable);

时间: 2024-11-05 16:25:20

Drawable和Bitmap区别的相关文章

Drawable与Bitmap 自定义

Drawable简介 Drawable是Android平下通用的图形对象,它可以装载常用格式的图像,比如GIF.PNG.JPG,当然也支持BMP.相比于View,我们并不需要去考虑如何measure.layout,仅仅只要去考虑如何draw(canavs). Though usually not visible to the application, Drawables may take a variety of forms 形式: Bitmap: the simplest Drawable,

Android Drawable、Bitmap、byte[]之间的转换

转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } else if (drawable instanceof NinePatch

Drawable和Bitmap转换

一.Bitmap转Drawable Bitmap mBitMap=getYourBitMap(); //getYourBitMap()是你获取BitMap的方法 BitmapDrawable mBitDrawable=new BitmapDrawable(mBitMap); //BtimapDrawable是Drawable的子类,直接把mBitDrawable对象当作Drawable使用即可. 二. Drawable转Bitmap Drawable mDrawable=getYourDrawa

Android -- Drawable与Bitmap

Drawable                                                                                 以下这个是测试加载1000个Drawable对象的代码: public class Main extends Activity { int number = 1000; Drawable[] array; @Override public void onCreate(Bundle savedInstanceState)

简单谈谈Resource,Drawable和Bitmap之间的转换

一直接触这些东西,还是归个类整理一下比较好. Resource -> Drawable Drawable draw1 = this.getResources().getDrawable(R.drawable.icon); Drawable -> Bitmap 1. static Bitmap drawableToBitmap(Drawable drawable) // drawable 转换成bitmap { int width = drawable.getIntrinsicWidth();/

Drawable转换为Bitmap两种方法

如果通过网络加载了一张位图,想拿到这张位图的Bitmap,有两种办法,至于那种好,可能要看是在什么情况下了 1,根据已有的Drawable创建一个新的Bitmap: private Bitmap bitmap;private void drawableToBitamp(Drawable drawable) { int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); System.out.printl

Drawable、Bitmap、byte[]之间的转换

1.Drawable → Bitmap Java代码   public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARG

SimpleAdapter中使用Drawable和Bitmap对象的方法

我们平常使用SimpleAdapter作为ListView或GridView适配器时,如果要显示图片,我们通常使用图片的id即R.drawable.xxx的方式来将图片绑定到视图上. 但是,如果我们要使用的图片是个Drawable或Bitmap对象时,上面的方式就不能解决问题了.下面就介绍如何在SimpleAdapter中使用Drawable或Bitmap对象. 1.使用Drawable对象作为SimpleAdapter要适配的图片资源 SimpleAdapter adapter=new Sim

Drawable与Bitmap(转)

Drawable                                                                                 以下这个是测试加载1000个Drawable对象的代码: public class Main extends Activity { int number = 1000; Drawable[] array; @Override public void onCreate(Bundle savedInstanceState)