Android Image Processing Bitmap class (1)

Source: Internet
Author: User

Bitmap is one of the most important classes of image processing in an Android system. It can get image file information, make image cut, rotate, zoom and so on, and can save image file in specified format. From the perspective of application, this paper emphatically introduces how to use bitmap to realize these functions.

First, the generation of bitmap

1.1 Bitmapfactory decode out bitmap

The bitmap is implemented in the Android.graphics package. However, the constructors of the bitmap class are private and cannot be instantiated outside, only through JNI instantiation. This is necessarily a helper class that provides an interface for creating bitmap, and the implementation of this class is instantiated bitmap by the JNI interface, which is bitmapfactory.

Using bitmapfactory , you can use decodefile() to solve the bitmap from a specified file, or you can define a picture resource by using the Decoderesource() Solve the bitmap.

1) created according to the resource file: Bitmap bmp = Bitmapfactory.decoderesource (|this.| Getresources (), P.DRAWABLE.BMPSRC);

2) According to the image creation: * Image files such as:/sdcard/dcim/tianjin.jpeg;

Bitmap bmp = Bitmapfactory.decodefile ("/sdcard/dcoim/tianjin.jpeg");

Options when 1.2 decode

When you use Method DecodeFile ()/decoderesource (), you can specify a bitmapfacotry. Options.

You can specify options for decode by using the following properties of the options:

    • INPREFERREDCONFIG specifies decode to memory, the encoding used in the phone, and the optional value defined in Bitmap.config. The default value is argb_8888.
    • Injustdecodebounds if set to true, does not completely decode the image data, that is, the DECODEXYZ () return value is null, but the options of the OUTABC to solve the basic information of the image.
    • Insamplesize the scale at which the decode is set.

Using these values of the options, you can efficiently get a thumbnail image.

First set injustdecodebounds= true, call DecodeFile () to get the basic information of the image [Step#2~4];

Using the width of the image (or height, or synthesis) and the width of the target, get the Insamplesize value, set injustdecodebounds= false, call DecodeFile () to get the complete image data [step#5~8].

To get the scale, and then read the data, if you want to read into the large scale reduction of the graph, will significantly save the content resources. Sometimes you read a lot of thumbnails, which is even more obvious.

Android Image Processing Bitmap class (1)

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.