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