Imageview. setimagebitmap (Bitmap)
Obtain bitmap from Res:
Bitmap bitmap = bitmapfactory. decoderesource (getresources (), R. drawable. XXX );
Obtain bitmap from bytearray:
Bitmap bitmap = bitmapfactory. decodebytearray (data, 0, Data. Length );
Obtain bitmap from a file:
Bitmap bitmap = bitmapfactory. decodefile (file_path );
Bitmapregiondecoder:
Parcelfiledescriptor filedescriptor = parcelfiledescriptor. Open (
File, parcelfiledescriptor. mode_read_only );
Bitmapregiondecoder decoder = bitmapregiondecoder. newinstance (filedescriptor. getfiledescriptor (), false );
Bitmap bitmap = decoder. decoderegion (New rect (0, 0, decoder. getwidth (), decoder. getheight (), null );
The problem of distortion in the Image view when the image is converted to bitmap:
Add options attributes
Options opts = new options ();
Opts. indensity = displaymetrics. density_default;
Bitmap bitmap = bitmapfactory. decodefile (file_path, opts );
Bitmap bitmap = bitmapfactory. decodebytearray (data, 0, Data. length, opts );