Bitmap(位图)的理解

来源:互联网 发布:python 显示 字符集 编辑:程序博客网 时间:2024/06/06 02:43

1.Bitmap(位图):

我们可以把他看作一个画架,我们先把画放到上面,然后我们可以 进行一些处理,比如获取图像文件信息,做旋转切割,放大缩小等操作!

2.Bitmap常用方法

public boolean compress (Bitmap.CompressFormat format, int quality, OutputStream stream) 
将位图的压缩到指定的OutputStream,可以理解成将Bitmap保存到文件中! 

format:格式,PNG,JPG等; 

quality:压缩质量,0-100,0表示最低画质压缩,100最大质量(PNG无损,会忽略品质设定) 

stream:输出流 

返回值代表是否成功压缩到指定流!

public void recycle()——回收位图占用的内存空间,把位图标记为Dead 
public final boolean isRecycled() ——判断位图内存是否已释放 
public final int getWidth()——获取位图的宽度 
public final int getHeight()——获取位图的高度 
public final boolean isMutable()——图片是否可修改 
public int getScaledWidth(Canvas canvas)——获取指定密度转换后的图像的宽度 
public int getScaledHeight(Canvas canvas)——获取指定密度转换后的图像的高度 

3.常用的静态方法: 

public static Bitmap createBitmap(Bitmap src) ——以src为原图生成不可变得新图像 
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, 
            int dstHeight, boolean filter)——以src为原图,创建新的图像,指定新图像的高宽以及是否可变。 
public static Bitmap createBitmap(int width, int height, Config config)——创建指定格式、大小的位图 
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height)以source为原图,创建新的图片,指定起始坐标以及新图像的高宽。 
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter) 


BitmapFactory工厂类: 
Option 参数类: 

public boolean inJustDecodeBounds——如果设置为true,不获取图片,不分配内存,但会返回图片的高度宽度信息。 
public int inSampleSize——图片缩放的倍数。如果设为4,则宽和高都为原来的1/4,则图是原来的1/16。 
public int outWidth——获取图片的宽度值 
public int outHeight——获取图片的高度值 
—————————————————————————————— 
public int inDensity——用于位图的像素压缩比 
public int inTargetDensity——用于目标位图的像素压缩比(要生成的位图) 
public boolean inScaled——设置为true时进行图片压缩,从inDensity到inTargetDensity。 

读取一个文件路径得到一个位图。如果指定文件为空或者不能解码成文件,则返回NULL。 
public static Bitmap decodeFile(String pathName, Options opts) 
public static Bitmap decodeFile(String pathName) 
读取一个资源文件得到一个位图。如果位图数据不能被解码,或者opts参数只请求大小信息时,则返回NuLL。 
(即当Options.inJustDecodeBounds=true,只请求图片的大小信息。) 
public static Bitmap decodeResource(Resources res, int id) 
public static Bitmap decodeResource(Resources res, int id, Options opts) 
从输入流中解码位图 
public static Bitmap decodeStream(InputStream is) 
从字节数组中解码生成不可变的位图 
public static Bitmap decodeByteArray(byte[] data, int offset, int length) 

BitmapDrawable类:继承于Drawable,你可以从文件路径、输入流、XML文件以及Bitmap中创建。 
常用的构造函数: 
Resources res=getResources();//获取资源 
public BitmapDrawable(Resources res)——创建一个空的drawable。(Response用来指定初始时所用的像素密度)替代public BitmapDrawable()方法(此方法不处理像素密度) 
public BitmapDrawable(Resources res, Bitmap bitmap)——Create drawable from a bitmap 
public BitmapDrawable(Resources res, String filepath)——Create a drawable by opening a given file path and decoding the bitmap. 
public BitmapDrawable(Resources res, java.io.InputStream is)——Create a drawable by decoding a bitmap from the given input stream. 


Bitmap对图片的处理:

http://www.cnblogs.com/feisky/archive/2010/01/10/1643460.html

http://my.oschina.net/rengwuxian/blog/182885



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 冰团e购扫码注册怎么办 苏宁销售火爆怎么办 菲洛城平台黑钱怎么办 货车扣12分怎么办 烟草证下来后怎么办 余款未结该怎么办 沙袋吸盘吸不住怎么办 电视购物不退货怎么办 母亲相信电视购物怎么办 中关村商城会买到假货怎么办 年休 科室主任不同意怎么办 怡成血糖仪不准怎么办 电子血压仪不准怎么办 学java没思路怎么办 安逸花评分不足怎么办 环保投诉不管用怎么办 乐购超市会员卡怎么办 易购225冻结金额怎么办 麻将机不洗牌了怎么办 麻将桌升不起来怎么办 公司宣布破产债务怎么办 一元乐购被骗怎么办 车被墙外皮砸了怎么办 win10安全中心打不开怎么办 导航出现001错误怎么办 车导航代码错误怎么办 买了假化妆品怎么办 发物流没有单号怎么办 天添网密码忘了怎么办 新华书香卡过期怎么办 车险断了一年怎么办 天添新倒闭捷信怎么办 建行diy信用卡怎么办卡 奥体 游泳卡过期怎么办 次卡过期了怎么办 该插件不受支持怎么办 信用卡申请找不到住址怎么办 中信信用卡白户怎么办 空调外铜管裸露怎么办 空调铜管露出来怎么办 小米分期后退货怎么办