Android image QR code identification and Preservation (ii)

Source: Internet
Author: User

Continue on an article, develop the image QR code recognition function, our performance analysis of the function of memory consumption significantly improved, do not use the function memory consumption is about 147M, using this feature many times later, up to 203M.

Therefore, the function of the study, found that each generation of images are not immediately released, resulting in in-memory images continue to accumulate, memory consumption continues to climb. Therefore, the need to release the image, release, when the need for special attention to the place is:

1. Release the status of the attention picture.

2. Note the catch of the exception.

Here is the code for the image release.

/**      * Recycle bitmap     */public    staticvoid  Recyclebitmap ( Bitmap Bitmap) {        ifnull &&!  Bitmap.isrecycled ()) {            bitmap.recycle ();             NULL ;        }           }

For the exception of the capture is mainly need to pay attention to the image in the process of encode and decode, the original method should be changed as follows:

 Public StaticResult Handleqrcodeformbitmap (Bitmap Bitmap) {Map<decodehinttype, object> hints =NewEnummap<> (Decodehinttype.class); Hints.put (Decodehinttype.character_set,"Utf-8");        Hints.put (Decodehinttype.try_harder, boolean.true);        Hints.put (Decodehinttype.possible_formats, Barcodeformat.qr_code); Rgbluminancesource Source=NULL; Qrcodereader Reader2=NULL; Result result=NULL; Try{Source=NewRgbluminancesource (bitmap); Binarybitmap Bitmap1=NewBinarybitmap (NewHybridbinarizer (source)); Reader2 =NewQrcodereader (); Result=Reader2.decode (BITMAP1, hints); } Catch(Exception e) {e.printstacktrace (); if(Source! =NULL&& Reader2! =NULL) {Binarybitmap bitmap2=NewBinarybitmap (NewGlobalhistogrambinarizer (source));Try{result=Reader2.decode (BITMAP2, hints); } Catch(Exception E1) {e1.printstacktrace (); }            }        }        returnresult; }

Of course, there are other optimization methods for the entire process, such as saving the picture format Compression scale are adjusted, without affecting the recognition of the premise, the image processing, which can save CPU time and save memory overhead.

If you have other better options, please ask.

Android image QR code identification and Preservation (ii)

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.