android Drawable setbounds()介绍

一、Drawable相关概念

1、Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable),我们根据画图的需求,创建相应的可画对象
2、Canvas画布,绘图的目的区域,用于绘图
3、Bitmap位图,用于图的处理
4、Matrix矩阵

二、Bitmap

1、从资源中获取Bitmap
Java代码  收藏代码
  1. Resources res = getResources();  
  2. Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.icon);  

 

2、Bitmap → byte[]
Java代码  收藏代码
  1. public byte[] Bitmap2Bytes(Bitmap bm) {  
  2.     ByteArrayOutputStream baos = new ByteArrayOutputStream();  
  3.     bm.compress(Bitmap.CompressFormat.PNG, 100, baos);  
  4.     return baos.toByteArray();  
  5. }  
 3、byte[] → Bitmap
Java代码  收藏代码
  1. public Bitmap Bytes2Bimap(byte[] b) {  
  2.     if (b.length != 0) {  
  3.         return BitmapFactory.decodeByteArray(b, 0, b.length);  
  4.     } else {  
  5.         return null;  
  6.     }  
  7. }  
4、Bitmap缩放
Java代码  收藏代码
  1. public static Bitmap zoomBitmap
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值