Bitmap

一张位图所占用的内存:图片长度(px) x 图片宽度(px)x 一个像素点所占的字节数

在Android中,存储一个像素点所占用的字节数是使用枚举类型Bitmap.Config中的各个参数来表示的参数如下:

ALPHA_8:表示8位Alpha位图,即A=8,不存储其他颜色,一个像素点占用1字节,只有透明度没有颜色
ARGB_4444:表示16位ARGB图,A、R、G、B各占用4位,一个像素点占4+4+4+4=16位,2字节
ARGB_8888:表示32位ARGB图,A、R、G、B各占用8位,一个像素点占8+8+8+8=32位,4字节
RGB_565:表示16位RGB位图,即R占5位,G占6位,B占5位,没有透明度

BitmapFactory
BitmapFactory用于从各种资源,文件,数据流和字节数组中创建Bitmap对象,BitmapFactory是一个工具类,提供了大量的函数,可以用于从不同的数据源中解析、创建Bitmap对象

从资源中解码一张位图,主要以R.drawable.xxx的形式从本地资源中加载
public static Bitmap decodeResource(Resource res, int id);
public static Bitmap decodeResource(Resource res, int id, Options opts)

文件中读取 pathName:解码文件的全路径名,必须是路径全名
public static Bitmap decodeFile(String pathName);
public static Bitmap decodeFile(String pathName, Options opts);

数组中读取
public static Bitmap decodeByteArray(byte[] data, int offset, int length);
public static Bitmap decodeByteArray(byte[] data, int offset, int length, Options opts);
public static Bitmap decodeFileDescriptor(FileDescriptor fd);
public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts);

从输入流中读取,
public static Bitmap decodeStream(InputStream is);
public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts);
public static Bitmap decodeResourceStream(Resources res, TypeValue value, InputStream is, Rect padding, Options opts);
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值