Bitmap实现在android.graphics包中。但是Bitmap类的构造函数是私有的,外面并不能实例化,只能是通过JNI实例化。这必然是 某个辅助类提供了创建Bitmap的接口,而这个类的实现通过JNI接口来实例化Bitmap的,这个类就是BitmapFactory
BitmapFactory
extends Object
java.lang.Object | |
↳ | android.graphics.BitmapFactory |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
data, int offset, int length, BitmapFactory.Options opts) Decode an immutable bitmap from the specified byte array.
|
||||||||||
|
data, int offset, int length)从字节数组中解码出Bitmap Decode an immutable bitmap from the specified byte array.
|
||||||||||
|
Decode a file path into a bitmap.
|
||||||||||
|
Decode a file path into a bitmap.
|
||||||||||
|
Decode a bitmap from the file descriptor.
|
||||||||||
|
BitmapFactory.Options为解码参数 Decode a bitmap from the file descriptor.
|
||||||||||
|
int id, BitmapFactory.Options opts) Synonym for opening the given resource and calling
decodeResourceStream(Resources, . |
||||||||||
|
int id) Synonym for
decodeResource(Resources, will null Options.Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic180);
|
||||||||||
|
Decode a new Bitmap from an InputStream.
|
||||||||||
|
Decode an input stream into a bitmap.
|
||||||||||
|
BitmapFactory.Options为解码参数 Decode an input stream into a bitmap.
|
public Bitmap inBitmap
public int inDensity
public boolean inDither
public boolean inInputShareable
public boolean inJustDecodeBounds 如果设置为true,并不会把图像的数据完全解码,亦即decodeXyz()返回值为null,但是Options的outAbc中解出了图像的基本信息。
public boolean inMutable
public boolean inPreferQualityOverSpeed
public Bitmap.Config inPreferredConfig 指定decode到内存中,手机中所采用的编码,可选值定义在Bitmap.Config中。缺省值是ARGB_8888。
public boolean inPurgeable
public int inSampleSize 设置decode时的缩放比例
public boolean inScaled
public int inScreenDensity
public int inTargetDensity
public byte[] inTempStorage
public boolean mCancel
public int outHeight 指定解码出来的高度
public String outMimeType 指定解码出来的MimeType
public int outWidth 指定解码出来的宽度
2、Bitmap bitmap=bitmapDrawable.getBitmap();
二、// 转换为BitmapDrawable对象
1、BitmapDrawable bmpDraw=new BitmapDrawable(bitmap);
2、BitmapDrawable bitmapDrawable=new BitmapDrawable(InputStream);
3、BitmapDrawable bmpDraw=(BitmapDrawable)getResources().getDrawable(R.drawable.pic180);