现在的位置: 首页 > 综合 > 正文

andriod.graphics.BitmapFactory类详解

2018年05月01日 ⁄ 综合 ⁄ 共 2766字 ⁄ 字号 评论关闭

Bitmap实现在android.graphics包中。但是Bitmap类的构造函数是私有的,外面并不能实例化,只能是通过JNI实例化。这必然是 某个辅助类提供了创建Bitmap的接口,而这个类的实现通过JNI接口来实例化Bitmap的,这个类就是BitmapFactory

public class

BitmapFactory

extends Object

java.lang.Object
   ↳ android.graphics.BitmapFactory
Public Constructors
BitmapFactory()
Public Methods
static Bitmap decodeByteArray(byte[]
data, int offset, int length, BitmapFactory.Options opts)
Decode an immutable bitmap from the specified byte array.
static Bitmap decodeByteArray(byte[]
data, int offset, int length)从字节数组中解码出Bitmap
Decode an immutable bitmap from the specified byte array.
static Bitmap decodeFile(String pathName)从文件路径解码出Bitmap
Decode a file path into a bitmap.
static Bitmap decodeFile(String pathName, BitmapFactory.Options opts)BitmapFactory.Options为解码参数
Decode a file path into a bitmap.
static Bitmap decodeFileDescriptor(FileDescriptor fd)从一个文件描述符解码出Bitmap
Decode a bitmap from the file descriptor.
static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts)从一个文件描述符解码出Bitmap,以矩阵outPadding为大小,
BitmapFactory.Options为解码参数
Decode a bitmap from the file descriptor.
static Bitmap decodeResource(Resources res,
int id, BitmapFactory.Options opts)
static Bitmap decodeResource(Resources res,
int id)
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic180);
static Bitmap decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad, BitmapFactory.Options opts)
Decode a new Bitmap from an InputStream.
static Bitmap decodeStream(InputStream is)
Decode an input stream into a bitmap.
static Bitmap decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts)从inputStream中解码出Bitmap,以矩阵outPadding为大小,
BitmapFactory.Options为解码参数
Decode an input stream into a bitmap.

BitmapFactory.Options

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);

抱歉!评论已关闭.