Most visited

Recently visited

Added in API level 1

BitmapFactory

public class BitmapFactory
extends Object

java.lang.Object
   ↳ android.graphics.BitmapFactory


从各种来源创建位图对象,包括文件,流和字节数组。

Summary

Nested classes

class BitmapFactory.Options

 

Public constructors

BitmapFactory()

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)

将输入流解码为位图。

Inherited methods

From class java.lang.Object

Public constructors

BitmapFactory

Added in API level 1
BitmapFactory ()

Public methods

decodeByteArray

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
Bitmap decodeResource (Resources res, 
                int id)

带有空选项的 decodeResource(Resources, int, android.graphics.BitmapFactory.Options)同义词。

Parameters
res Resources: The resources object containing the image data
id int: The resource id of the image data
Returns
Bitmap The decoded bitmap, or null if the image could not be decoded.

decodeResource

Added in API level 1
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)

decodeResourceStream

Added in API level 4
Bitmap decodeResourceStream (Resources res, 
                TypedValue value, 
                InputStream is, 
                Rect pad, 
                BitmapFactory.Options opts)

从InputStream解码新的位图。 这个InputStream是从资源中获得的,我们通过这些资源可以相应地缩放位图。

Parameters
res Resources
value TypedValue
is InputStream
pad Rect
opts BitmapFactory.Options
Returns
Bitmap

decodeStream

Added in API level 1
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

Added in API level 1
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 ,这不再是这种情况。

Hooray!