Android的BitmapFactory的使用

来源:互联网 发布:列强瓜分中国知乎 编辑:程序博客网 时间:2024/05/20 09:10

使用BitmapFactory可以将读取流,文件,byte 数组转换成Bitmap对象

例如:Bitmap bitmap = BitmapFactory.decodeStream(inputStream);img_pic.setImageBitmap(bitmap);//为ImageView设置图片

API如下:

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)Decode an immutable bitmap from the specified byte array.static Bitmap   decodeFile(String pathName)Decode a file path into a bitmap.static Bitmap   decodeFile(String pathName, BitmapFactory.Options opts)Decode a file path into a bitmap.static Bitmap   decodeFileDescriptor(FileDescriptor fd)Decode a bitmap from the file descriptor.static Bitmap   decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts)Decode a bitmap from the file descriptor.static Bitmap   decodeResource(Resources res, int id, BitmapFactory.Options opts)Synonym for opening the given resource and calling decodeResourceStream(Resources, TypedValue, InputStream, Rect, BitmapFactory.Options).static Bitmap   decodeResource(Resources res, int id)Synonym for decodeResource(Resources, int, android.graphics.BitmapFactory.Options) will null Options.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)Decode an input stream into a bitmap.