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)