Android Bitmapfactory.Options


图片的使用,是我们经常要用到的,对图片的操作也是必须掌握的,比如压缩。在上一篇博客,我们讲到了质量压缩,比例压缩,


在比例压缩中,我们讲到了一个类:bitmapfactory.options

 
既然存在于bitmapfactory中,那么他必定是对图像进行操作,在上一篇博客,我们用到了他的一个属性:inJustDecodeBounds。今天介绍其他的属性:


Fields:

 
public Bitmap inBitmapIf set, decode methods that take the Options object will attempt to reuse this bitmap when loading content.
public int inDensityThe pixel density to use for the bitmap.
public boolean inDitherIf dither is true, the decoder will attempt to dither the decoded image.
public boolean inInputShareableThis field was deprecated in API level 21. As ofLOLLIPOP, this is ignored. In KITKAT and below, this field works in conjuction with inPurgeable. If inPurgeable is false, then this field is ignored. If inPurgeable is true, then this field determines whether the bitmap can share a reference to the input data (inputstream, array, etc.) or if it must make a deep copy.
public boolean inJustDecodeBoundsIf set to true, the decoder will return null (no bitmap), but the out...
public boolean inMutableIf set, decode methods will always return a mutable Bitmap instead of an immutable one.
public boolean inPreferQualityOverSpeedIf inPreferQualityOverSpeed is set to true, the decoder will try to decode the reconstructed image to a higher quality even at the expense of the decoding speed.
public Bitmap.Config inPreferredConfigIf this is non-null, the decoder will try to decode into this internal configuration.
public boolean inPremultipliedIf true (which is the default), the resulting bitmap will have its color channels pre-multipled by the alpha channel.
public boolean inPurgeableThis field was deprecated in API level 21. As ofLOLLIPOP, this is ignored. In KITKAT and below, if this is set to true, then the resulting bitmap will allocate its pixels such that they can be purged if the system needs to reclaim memory. In that instance, when the pixels need to be accessed again (e.g. the bitmap is drawn, getPixels() is called), they will be automatically re-decoded.

For the re-decode to happen, the bitmap must have access to the encoded data, either by sharing a reference to the input or by making a copy of it. This distinction is controlled by inInputShareable. If this is true, then the bitmap may keep a shallow reference to the input. If this is false, then the bitmap will explicitly make a copy of the input data, and keep that. Even if sharing is allowed, the implementation may still decide to make a deep copy of the input data.

While inPurgeable can help avoid big Dalvik heap allocations (from API level 11 onward), it sacrifices performance predictability since any image that the view system tries to draw may incur a decode delay which can lead to dropped frames. Therefore, most apps should avoid using inPurgeable to allow for a fast and fluid UI. To minimize Dalvik heap allocations use theinBitmap flag instead.

Note: This flag is ignored when used with decodeResource(Resources, int, android.graphics.BitmapFactory.Options) ordecodeFile(String, android.graphics.BitmapFactory.Options).

public int inSampleSizeIf set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory.
public boolean inScaledWhen this flag is set, if inDensity andinTargetDensity are not 0, the bitmap will be scaled to matchinTargetDensity when loaded, rather than relying on the graphics system scaling it each time it is drawn to a Canvas.
public int inScreenDensityThe pixel density of the actual screen that is being used.
public int inTargetDensityThe pixel density of the destination this bitmap will be drawn to.
public byte[] inTempStorageTemp storage to use for decoding.
public boolean mCancelFlag to indicate that cancel has been called on this object.
public int outHeightThe resulting height of the bitmap.
public String outMimeTypeIf known, this string is set to the mimetype of the decoded image.
public int outWidthThe resulting width of the bitmap.


以上是从sdk文档里面拿来的


inPurgeable

是控制 Bitmap 对象是否使用软引用机制, 软引用机制,是java的回收机制,与强引用机制的区别在于用完之后是否会被回收

inInputShareable

 与inPurgeable 组合使用的, 是控制是否复制 inputfile 对象的引用

inJustDecodeBounds

如果将这个值置为true,那么在解码的时候将不会返回bitmap,只会返回这个bitmap的尺寸。这个属性的目的是,如果你只想知道一个bitmap的尺寸,但又不想将其加载到内存时。上一篇博客在比例压缩时候用到过

inPreferredConfig

这个值是设置色彩模式,默认值是ARGB_8888,代表八位的透明度,蓝。绿,红,所以是四个字节,在一般情况下使用的是rgb-565,只需要两个字节(好像现在bitmap默认是它了,具体不清楚)

inPremultiplied

这个值和透明度通道有关,默认值是true,因为不常用,所以不涉猎透明度通道的知识。

inDither

这个值和抖动解码有关,默认值为false,表示不采用抖动解码。抖动解码是避免出现断带的处理,具体请看这边博客:http://blog.csdn.net/zouxueping/article/details/6796225,写的不错

inDensity

表示这个bitmap的像素密度。

inTargetDensity

表示要被画出来时的目标像素密度

inScreenDensity

表示实际设备的像素密度

inScaled

设置这个Bitmap是否可以被缩放,默认值是true,表示可以被缩放。

inSampleSize:(采样率)

这个值是一个int,当它小于1的时候,将会被当做1处理,如果大于1,那么就会按照比例(1 / inSampleSize)缩小bitmap的宽和高、降低分辨率,大于1时这个值将会被处置为2的倍数。例如,width=100,height=100,inSampleSize=2,那么就会将bitmap处理为,width=50,height=50,宽高降为1 / 2,像素数降为1 / 4。注意:insamplesize的处理必须是2的n次方,因为只能是2的n次方,比如一张图片,我们要求是原来的八分之一,那么采样率正好实现,但是十五分之一,却默认为十六分之一,所以采样率有时很不准确,建议使用matrix处理

最后:

options类主要是处理bitmap的压缩



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值