Android: imageview and bitmap

Source: Internet
Author: User

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









Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.