android graphics--AvoidXfermode/Bitmap/BitmapFactory译

纯属根据文档进行翻译,有错误请告之:   持续更新中.......

Xfermode

Xfermode是对象的基类,在绘制管道实现自定义“transfer-modes”时将被回调。在枚举模式中,静态创建模式的方法将会被回调以返回一个规定的预定义的子类的实例。Xfermode时被分配给一个Paint,然后拥有具有Xfermode应用的Paint的对象进行绘制。

以下为子类介绍:

AvoidXfermode

AvoidXfermode xfermode将绘制资源在除了顶部的任何位置,或者,依赖于模式,只绘制在顶部。

 

构造方法详细信息

AvoidXfermode

public AvoidXfermode(int opColor,
                     int tolerance,
                     AvoidXfermode.Mode mode)

opColor  用于规避或者依赖模式的颜色,注意二色上的阿尔法alpha透明度将会被忽略;

tolerance 我们对比2色像素的紧密度,如果精确匹配255 -最高等级(混合),只会在基于我们的opColor类似像素上进行操作

mode 如果我们要进行规避或者需要作为目标的opColor模式  枚举常量具有两种模式AOVID、TARGET;

 

PielXorXfermode

PixelXorXfermode实现一个简单的像素xor(op ^ src ^ dst)。这种转变并不遵循自左乘约定,因此这种模式* *总是返回一个不透明的颜色(α= = 255)。因此它不是真的有用操作混合颜色。

 

PorterDuffXfermode

创建一个使用指定的porter-duff xfermode模式。

构造方法摘要

PorterDuffXfermode(PorterDuff.Mode mode)

 

//

public final class Bitmap
     
     
      
      extends 
      
      Object
     
     
     
     
      
      implements 
      
      Parcelable
     
     
     
     
      
       
     
     

静态内部类有:

枚举

public static enum Bitmap.CompressFormat
     
     
      
      extends 
      
      Enum<
      
      Bitmap.CompressFormat>  为
      
      指定位图可以压缩成已知的格式的类,枚举常量有JPEG、PNG
     
     

方法摘要
static Bitmap.CompressFormatvalueOf(String name)
返回带有指定名称的该类型的枚举常量。
static Bitmap.CompressFormat[]values()
按照声明该枚举类型的常量的顺序,返回包含这些常量的数组。

public static enum Bitmap.Config
     
     
      
      extends 
      
      Enum<
      
      Bitmap.Config>   位图的配置枚举类,常量有ALPHA_8、RGB_565、ARGB_4444、ARGB_8888
     
     

static Bitmap.ConfigvalueOf(String name)
返回带有指定名称的该类型的枚举常量。
static Bitmap.Config[]values()
按照声明该枚举类型的常量的顺序,返回包含这些常量的数组。

 


字段详细信息

DENSITY_SCALE_UNKNOWN

public static final float DENSITY_SCALE_UNKNOWN  表示位图创建为一个未知的像素密度

CREATOR

public static final Parcelable.Creator<Bitmap> CREATOR  序列化
 
 
     
     
方法详细信息

getDensityScale

public float getDensityScale()
返回这个位图的密度范围,表示为一个默认的密度的因素(160)。例如,位图用于显示密度240将会有一个密度的规模1.5而位图设计密度的160将会有一个密度的1.0。

setDensityScale

public void setDensityScale(float densityScale)

指定位图的密度范围,表示为一个默认的密度的因素(160)。例如,位图用于显示密度240将会有一个密度的规模1.5而位图设计密度的160将会有一个密度的1.0。

参数densityScale -使用位图的密度比例,或者如果比例未知就表示未知的密度像素;

 

isAutoScalingEnabled

public boolean isAutoScalingEnabled()

表明这个位图在绘制时是否会自动扩展目标的密度图。如果启用了自动伸缩功能,这个位图绘制将用以下比例因子:

scale = (bitmap density scale factor)位图的密度比例因素 / (target density scale factor)  目标的密度比例

 自动伸缩功能默认是关闭的。如果启用了自动伸缩功能但是位图又是未知密度范围,那么位图在绘图时不会自动缩放。

返回:如果位图在绘制时自动缩放就返回真,否则假;

 

setAutoScalingEnabled

public void setAutoScalingEnabled(boolean autoScalingEnabled) 设置位图绘制时是否自动缩放

setNinePatchChunk

public void setNinePatchChunk(byte[] chunk)设置nine patch 块
参数:
chunk -定义的nine 块

recycle

public void recycle()

释放位图像素的内存,并且标记位图已经销毁;这意味着如果getPixels() or setPixels()回调的话将会抛出异常,并且什么也不会绘制;这个操作是不可逆转的,所有如果你确定不再使用这个位图的话就应该回调这个函数;这是一个提前的回调,正常的话不需要再回调,因为正常的GC进程将会在没有这位图的引用时释放这块内存。

 

isRecycled

public final boolean isRecycled() 位图内存是否已经被释放

如果已经释放,在获取其像素就会报异常,位图也不会绘制;

 

copyPixelsFromBuffer

public void copyPixelsFromBuffer(Buffer src)

从当前位置开始拷贝缓冲区的像素,以覆盖位图的像素。缓冲区的数据不论用什么方式都是不会改变的(不像setPixels(),它将从unpremultipled 32位格式到位图的原生格式。)

 

copyPixelsToBuffer

public void copyPixelsToBuffer(Buffer dst)

拷贝位图的像素到指定的缓冲区(由调用方分配),如果缓冲区不够大去容纳所有的像素这将抛出异常(考虑了每个像素的字节数),或者缓冲的子类不是以下支持类型之一(ByteBuffer, ShortBuffer, IntBuffer)

copy

public Bitmap copy(Bitmap.Config config,
                   boolean isMutable)

试图在原位图的尺寸上产生新的位图,设置一个指定新的位图的配置,,然后复制位图的像素到新位图,如果不支持转换,或分配失败,那么这将返回NULL。

 

参数:
config - 期望位图的像素配置
isMutable - 位图是否可变 (即像素是否可以修改)

 

createScaledBitmap

public static Bitmap createScaledBitmap(Bitmap src,
                                        int dstWidth,
                                        int dstHeight,
                                        boolean filter)

根据原始的位图,指定的宽、高,创建新位图,filter表示是否将原位图过滤。

 

createBitmap

public static Bitmap createBitmap(Bitmap src)

返回一个不可变的源位图的位图。新的位图可能是与源相同的对象,或可能是一个副本。

createBitmap

public static Bitmap createBitmap(Bitmap source,
                                  int x,
                                  int y,
                                  int width,
                                  int height)

从指定的源位图的子集返回一个不可变的位图,新的位图可能与源相同的对象,或可能是一个副本

参数:
source - 用于构造的位图
x - 资源第一个像素的x坐标
y - 资源第一个像素的y坐标
width - 每一行像素的数量
height - 行数createBitmap

createBitmap

public static Bitmap createBitmap(Bitmap source,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  Matrix m,
                                  boolean filter)

返回一个不可变的源位图的位图的子集,可选的矩阵转换。

m-应用到像素上的矩阵选项;

filter - 仅适用于矩阵包含不仅平移时;其他参数同上;

 

createBitmap

public static Bitmap createBitmap(int width,
                                  int height,
                                  Bitmap.Config config)

返回一个指定宽高的可变的位图。如果宽高小于0将抛出异常。

createBitmap

public static Bitmap createBitmap(int[] colors,
                                  int offset,
                                  int stride,
                                  int width,
                                  int height,
                                  Bitmap.Config config)

返回指定宽高不可变的位图,每个像素值设置为颜色数组的对应值。

参数:
colors - 初始化像素的颜色数组
offset - 颜色数组中第一个颜色的偏移位置
stride - 数组中行之间颜色的数量 (must be >= width or <= -width).
width - The width of the bitmap
height - The height of the bitmap
config - The bitmap config to create. If the config does not support per-pixel alpha (e.g. RGB_565), then the alpha bytes in the colors[] will be ignored (assumed to be FF)

createBitmap

public static Bitmap createBitmap(int[] colors,
                                  int width,
                                  int height,
                                  Bitmap.Config config)

返回指定宽高不可变的位图,每个像素值设置为颜色数组的对应值。

参数:
colors - 初始化像素的颜色数组,数组必须至少有 width * height大,否则抛出异常.
width - The width of the bitmap
height - The height of the bitmap
config - The bitmap config to create. If the config does not support per-pixel alpha (e.g. RGB_565), then the alpha bytes in the colors[] will be ignored (assumed to be FF)

getNinePatchChunk

public byte[] getNinePatchChunk()

返回私有数据的选项数组,被系统UI使用于一些位图上,不是为了被应用程序回调。

compress

public boolean compress(Bitmap.CompressFormat format,
                        int quality,
                        OutputStream stream)

以指定的图片格式和精度压缩位图到指定的输出流,如果压缩成功,位图可以通过相应的输入流到BitmapFactory.decodeStream()重构,注意,不是所有的位图配置都支持所有的格式,所有可能从BitmapFactory返回的位图的bitdepth(位深度)不同,也有可能损失alpha,例如JPEG只支持透明像素

isMutable

public final boolean isMutable()

位图是否可变(像素是否可改变)

getWidth

public final int getWidth()
Returns the bitmap's width


getHeight

public final int getHeight()
Returns the bitmap's height


getScaledWidth

public int getScaledWidth()返回被位图密度比例因素划分的位图的宽的便捷方法
返回:
The scaled width of this bitmap, according to the density scale factor.

getScaledHeight

public int getScaledHeight()同上

getRowBytes

public final int getRowBytes()返回位图一行的字节数
 

getConfig

public final Bitmap.Config getConfig()如果位图的内屏配置是位图公共格式之一,就返回配置,否则null
 

hasAlpha

public final boolean hasAlpha()是否支持透明
 

eraseColor

public void eraseColor(int c)用指定的颜色填充位图的像素,如果位图不可变,抛出状态异常;
 

getPixel

public int getPixel(int x,
                    int y)返回指定坐标位置的像素,如果x或y越界抛出异常

getPixels

public void getPixels(int[] pixels,
                      int offset,
                      int stride,
                      int x,
                      int y,
                      int width,
                      int height)

返回位图像素数据的副本,

参数:
pixels - 接收位图颜色的数组
offset - 写进数组的第一个下标
stride - 行之间,像素数组跳过的实体的数量
x - 从位图中读取的第一个像素的x坐标
y - 从位图中读取的第一个像素的x、y坐标
width - The number of pixels to read from each row
height - The number of rows to read

setPixels

public void setPixels(int[] pixels,
                      int offset,
                      int stride,
                      int x,
                      int y,
                      int width,
                      int height)

describeContents

public int describeContents()返回的对象类型的位掩码

writeToParcel

public void writeToParcel(Parcel p,
                          int flags)

将位图和其像素写进parcel中,位图可以重建的包裹通过调用CREATOR.createFromParcel()。

 

extractAlpha

public Bitmap extractAlpha()

返回一个捕捉了原始位图alpha的新位图,这可能是用Canvas.drawBitmap()进行绘制,颜色可能从paint上传递到绘制图上。

extractAlpha

public Bitmap extractAlpha(Paint paint,
                           int[] offsetXY)

返回一个捕捉了原始位图alpha的新位图,值可能受paint参数选项的影响,

参数:
paint - 修改位图alpha的可选paint,默认为空
offsetXY可选数组,返回位图的X(索引0)和Y(指数1)偏移位置
 

///

android.graphics
类 BitmapFactory

java.lang.Object
  继承者 android.graphics.BitmapFactory

嵌套类摘要
static classBitmapFactory.Options

字段详细信息

inJustDecodeBounds

public boolean inJustDecodeBounds 是否分配位图的内存位置,ture分配,false不分配,只获取了其大小
 

inSampleSize

public int inSampleSize 位图的压缩比例,大于1表示缩小,小于1和1一样,例如为表示宽的1/4高1/4,即像素的1/16大小;
 

inPreferredConfig

public Bitmap.Config inPreferredConfig
如果非空,译码器将尝试解码成这个内部配置。如果它为空,或请求无法满足,译码器将尝试挑选最好的匹配配置基于系统的屏幕深度,和原始图像的特征,如如果alpha(也需要配置)。

inDensity

public int inDensity位图期望的密度大小
 

inScaled

public boolean inScaled 如果位图是从资源加载并且标记为true,位图将会缩放以匹配默认显示的密度像素。
 

outWidth

public int outWidth返回的位图宽,依赖于inJustDecodeBounds的状态,然而解析的时候可能报错,可能被设置为-1.
 

outHeight

public int outHeight
 

outMimeType

public String outMimeType如果存在,将被设置为解析位图的类型
 

inTempStorage

public byte[] inTempStorage解析使用的临时存储区。
 

mCancel

public boolean mCancel表明对象的回调是否已经取消的标记
 
 
       
       
方法详细信息

decodeFile

public static Bitmap decodeFile(String pathName,
                                BitmapFactory.Options opts)
 

decodeFile

public static Bitmap decodeFile(String pathName)

decodeStream

public static Bitmap decodeStream(Resources res,
                                  TypedValue value,
                                  InputStream is,
                                  Rect pad,
                                  BitmapFactory.Options opts)
 

decodeResource

public static Bitmap decodeResource(Resources res,
                                    int id,
                                    BitmapFactory.Options opts)
 

decodeResource

public static Bitmap decodeResource(Resources res,
                                    int id)
 

decodeByteArray

public static Bitmap decodeByteArray(byte[] data,
                                     int offset,
                                     int length,
                                     BitmapFactory.Options opts)
 

decodeByteArray

public static Bitmap decodeByteArray(byte[] data,
                                     int offset,
                                     int length)
 

decodeStream

public static Bitmap decodeStream(InputStream is,
                                  Rect outPadding,
                                  BitmapFactory.Options opts)

decodeStream

public static Bitmap decodeStream(InputStream is)
 

decodeFileDescriptor

public static Bitmap decodeFileDescriptor(FileDescriptor fd,
                                          Rect outPadding,
                                          BitmapFactory.Options opts) 从指定的文件描述符中解析
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值