Xiaomi 3 The problem of loading album pictures on the phone failed

Source: Internet
Author: User



Model Millet 3w,rom4.4.4 nonsense not to say that in the load album picture times had such a mistake


09-16 12:26:53.270:w/openglrenderer (21987): Bitmap too large to BES uploaded into a texture (4208x2368, max=4096x4096)


Cut Bai, online find an algorithm, very good, posted here, recorded



In the process of doing photo album application, need to get a compressed thumbnail but, at the same time I also want to get the bitmap can be square, to adapt to the square imageview, the traditional setting insamplesize compression ratio of the way just compressed the entire picture, If a picture has a large gap between the length and width, then the display will have a stretch phenomenon, so the correct practice is after compression, the bitmap are cropped.



The code is as follows:



Captures the square portion of the middle of a given picture when it is scaled to maintain a width-to-height ratio


1 /**2 3  * @paramBitmap Original4  * @paramEdgelength want to get the square part of the side length5  * @returnzooms the bitmap after the median portion is captured. 6 */7  Public StaticBitmap Centersquarescalebitmap (Bitmap Bitmap,intedgelength)8  {9 if(NULL= = Bitmap | | Edgelength <= 0)Ten  { One return NULL; A  } -  -Bitmap result =bitmap; the intwidthorg =bitmap.getwidth (); - intheightorg =bitmap.getheight (); -  - if(widthorg > Edgelength && heightorg >edgelength) +  { - //compress to a minimum length of edgelength bitmap + intLongeredge = (int) (Edgelength * Math.max (widthorg, heightorg)/math.min (widthorg, heightorg)); A intScaledwidth = widthorg > heightorg?longeredge:edgelength; at intScaledheight = widthorg > heightorg?Edgelength:longeredge; - Bitmap Scaledbitmap; -  - Try{ -Scaledbitmap = Bitmap.createscaledbitmap (Bitmap, Scaledwidth, Scaledheight,true); -  } in Catch(Exception e) { - return NULL; to  } +  - //intercept the square part in the middle.  the intXtopleft = (scaledwidth-edgelength)/2; * intYtopleft = (scaledheight-edgelength)/2; $ Panax Notoginseng Try{ -result =Bitmap.createbitmap (Scaledbitmap, Xtopleft, Ytopleft, Edgelength, edgelength); the scaledbitmap.recycle (); +  } A Catch(Exception e) { the return NULL; +  }  -  } $  $ returnresult; -}


Note that the bitmap parameter must be obtained from the original image, if it has been bitmapfactory insamplesize compressed, may not be to the square.



The original page is here


Http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0917/1686.html






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.