Android Download image appears skimagedecoder::factory returned null,bitmapfactory.options compression

Source: Internet
Author: User

There are many online said that because no use of httpclient caused by, I changed to httpclient request the picture or will appear skimagedecoder::factory returned NULL,

But direct use

Bitmap = Bitmapfactory.decodestream (IS); is normal, but can't solve the problem of large memory overflow of picture

Workaround:

To retrieve the stream again, look at the Code (Red section):

/*** Get bitmap objects based on network URL *@paramURL *@paramwidth to get the widths *@paramheight to get to prevent memory overflow *@return     */     Public StaticBitmap returnbitmap (String URL,intWidthintheight) {Bitmap Bitmap=NULL; Try{httpget HttpRequest=Newhttpget (URL); LOG.D ("Returnbitmap", "url=" +URL); HttpClient HttpClient=Newdefaulthttpclient (); HttpResponse Response=(HttpResponse) Httpclient.execute (HttpRequest); Httpentity Entity=response.getentity (); Bufferedhttpentity bufferedhttpentity=Newbufferedhttpentity (entity); InputStream is=bufferedhttpentity.getcontent (); Bitmapfactory.options Options=Newbitmapfactory.options (); Options.injustdecodebounds=true;//get the high width of the picture only            intScale = 1; Bitmapfactory.decodestream (IS,NULL, Options); intW =Options.outwidth; inth =Options.outheight; LOG.D ("Returnbitmap", "w=" +w+ ", h=" +h+ "; width=" +width+ "; height=" +height);  while(true)            {                if((width>0 && w < width) | | (height>0 && H <height)) {                     Break; } W/= 2; H/= 2; Scale*= 2; } options.injustdecodebounds=false; Options.insamplesize=Scale ;   is= Bufferedhttpentity.getcontent ();//re-fetch streamBitmap = Bitmapfactory.decodestream (IS,NULL, Options); LOG.D ("Returnbitmap", "bitmap=" +bitmap+ (bitmap==NULL?" Bitmap is null ":" Bitmap is not NULL "));        Is.close (); } Catch(IOException e) {e.printstacktrace (); }         Catch(OutOfMemoryError e) {e.printstacktrace (); }          returnbitmap; }

This will be downloaded and displayed normally, oh yes!!!

Android Download image appears skimagedecoder::factory returned null,bitmapfactory.options compression

Related Article

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.