BitmapFactory
public class BitmapFactory
extends Object
从各种来源创建位图对象,包括文件,流和字节数组。
Summary
Public methods |
static Bitmap |
decodeByteArray(byte[] data, int offset, int length, BitmapFactory.Options opts) 解码指定字节数组中的不可变位图。 |
static Bitmap |
decodeByteArray(byte[] data, int offset, int length) 解码指定字节数组中的不可变位图。 |
static Bitmap |
decodeFile(String pathName, BitmapFactory.Options opts) 将文件路径解码为位图。 |
static Bitmap |
decodeFile(String pathName) 将文件路径解码为位图。 |
static Bitmap |
decodeFileDescriptor(FileDescriptor fd) 从文件描述符中解码一个位图。 |
static Bitmap |
decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts) 从文件描述符中解码一个位图。 |
static Bitmap |
decodeResource(Resources res, int id) 带有空选项的 decodeResource(Resources, int, android.graphics.BitmapFactory.Options) 同义词。 |
static Bitmap |
decodeResource(Resources res, int id, BitmapFactory.Options opts) 打开给定资源并致电 decodeResourceStream(Resources, TypedValue, InputStream, Rect, BitmapFactory.Options) 。 |
static Bitmap |
decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad, BitmapFactory.Options opts) 从InputStream解码新的位图。 |
static Bitmap |
decodeStream(InputStream is) 将输入流解码为位图。 |
static Bitmap |
decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) 将输入流解码为位图。 |
Public constructors
BitmapFactory
BitmapFactory ()
Public methods
decodeByteArray
Bitmap decodeByteArray (byte[] data,
int offset,
int length,
BitmapFactory.Options opts)
解码指定字节数组中的不可变位图。
Parameters |
data |
byte : byte array of compressed image data |
offset |
int : offset into imageData for where the decoder should begin parsing. |
length |
int : the number of bytes, beginning at offset, to parse |
opts |
BitmapFactory.Options : null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. |
Returns |
Bitmap |
The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) |
decodeByteArray
Bitmap decodeByteArray (byte[] data,
int offset,
int length)
解码指定字节数组中的不可变位图。
Parameters |
data |
byte : byte array of compressed image data |
offset |
int : offset into imageData for where the decoder should begin parsing. |
length |
int : the number of bytes, beginning at offset, to parse |
Returns |
Bitmap |
The decoded bitmap, or null if the image could not be decoded. |
decodeFile
Bitmap decodeFile (String pathName,
BitmapFactory.Options opts)
将文件路径解码为位图。 如果指定的文件名为空,或者无法解码为位图,则函数返回null。
Parameters |
pathName |
String : complete path name for the file to be decoded. |
opts |
BitmapFactory.Options : null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. |
Returns |
Bitmap |
The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) |
decodeFile
Bitmap decodeFile (String pathName)
将文件路径解码为位图。 如果指定的文件名为空,或者无法解码为位图,则函数返回null。
Parameters |
pathName |
String : complete path name for the file to be decoded. |
Returns |
Bitmap |
the resulting decoded bitmap, or null if it could not be decoded. |
decodeFileDescriptor
Bitmap decodeFileDescriptor (FileDescriptor fd)
从文件描述符中解码一个位图。 如果位图无法解码,则返回null。 描述符中的位置在返回时不会改变,所以描述符可以按原样再次使用。
Parameters |
fd |
FileDescriptor : The file descriptor containing the bitmap data to decode |
Returns |
Bitmap |
the decoded bitmap, or null |
decodeFileDescriptor
Bitmap decodeFileDescriptor (FileDescriptor fd,
Rect outPadding,
BitmapFactory.Options opts)
从文件描述符中解码一个位图。 如果位图无法解码,则返回null。 描述符中的位置在返回时不会更改,因此描述符可以按原样再次使用。
Parameters |
fd |
FileDescriptor : The file descriptor containing the bitmap data to decode |
outPadding |
Rect : If not null, return the padding rect for the bitmap if it exists, otherwise set padding to [-1,-1,-1,-1]. If no bitmap is returned (null) then padding is unchanged. |
opts |
BitmapFactory.Options : null-ok; Options that control downsampling and whether the image should be completely decoded, or just its size returned. |
Returns |
Bitmap |
the decoded bitmap, or null |
decodeResource
Bitmap decodeResource (Resources res,
int id,
BitmapFactory.Options opts)
打开给定资源并致电 decodeResourceStream(Resources, TypedValue, InputStream, Rect, BitmapFactory.Options)
。
Parameters |
res |
Resources : The resources object containing the image data |
id |
int : The resource id of the image data |
opts |
BitmapFactory.Options : null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. |
Returns |
Bitmap |
The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) |
decodeStream
Bitmap decodeStream (InputStream is)
将输入流解码为位图。 如果输入流为空,或者不能用于解码位图,则函数返回null。 流的位置将是编码数据读取后的位置。
Parameters |
is |
InputStream : The input stream that holds the raw data to be decoded into a bitmap. |
Returns |
Bitmap |
The decoded bitmap, or null if the image data could not be decoded. |
decodeStream
Bitmap decodeStream (InputStream is,
Rect outPadding,
BitmapFactory.Options opts)
将输入流解码为位图。 如果输入流为空,或者不能用于解码位图,则函数返回null。 流的位置将是编码数据读取后的位置。
Parameters |
is |
InputStream : The input stream that holds the raw data to be decoded into a bitmap. |
outPadding |
Rect : If not null, return the padding rect for the bitmap if it exists, otherwise set padding to [-1,-1,-1,-1]. If no bitmap is returned (null) then padding is unchanged. |
opts |
BitmapFactory.Options : null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. |
Returns |
Bitmap |
The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) 在KITKAT 之前,如果is.markSupported() 返回true, is.mark(1024) 调用is.mark(1024) 。 截至KITKAT ,这不再是这种情况。 |