Android中的Bitmap和Drawable分析

  • Post author:
  • Post category:其他


最近比较闲,开始整理下接触到的东西吧,加深一下对一些知识点的认识,一直对Android中的Bitmap和Drawable认识比较模糊,用起来也是迷迷糊糊的,所以首先对这两个类做一些分析吧(一般我们可以在官网上查看相关api或是直接在AS里面点进去查看类的源码)

1. Bitmap 与 Drawable区别

首先看看Drawable类的注释

>   A Drawable is a general abstraction for “something that can be drawn.”

>   Most often you will deal with Drawable as the type of resource retrieved for

>   drawing things to the screen; the Drawable class provides a generic API for

>   dealing with an underlying visual resource that may take a variety of forms.

>   Unlike a {@link android.view.View}, a Drawable does not have any facility to

>   receive events or otherwise interact with the user.

Drawable是一个抽象类,代表的是“可绘制的东西”的一般抽象。通常你会将Drawable作为绘制事物到屏幕上的资源类型来处理,它提供了一个通用API来处理可能采用多种形式的底层视觉资源。与View不同的是,Drawable没有任何接收事件或以其他方式与用户交互的功能。平常我们使用的时候都是res目录下创建相应的drawable资源,比如button的背景图片,背景颜色,以及button不同的状态的动画效果等。

然后接着看下面一段注释

Though usually not visible to the application, Drawables may take a variety of forms:

>   Bitmap: the simplest Drawable, a PNG or JPEG image.

>   Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.

>   Vector: a drawable defined in an XML file as a set of points, lines, and curves along with its associated color information. This type of drawable can be scaled without loss of display quality.

>   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.



版权声明:本文为caijie2525原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。