For my current application I collect images from different \"event providers\" in Spain.
Bitmap bmp=null;
HttpGet httpRequest = new HttpGet(strURL);
l
I was having a similar problem, and the root issue was due to timeouts when requesting some images. I switched to using a Background Image Loader and have had no problems since. Hope this helps
HttpURLConnection hConn = null;
hConn = openHttpConnection(szUrl);
hConn.setRequestMethod("GET");
hConn.setRequestProperty("User-Agent",szUserAgent);
hConn.setRequestProperty("Accept",szAccept);
hConn.setRequestProperty("Accept-Charset",szCharset);
hConn.setInstanceFollowRedirects(true);
hConn.setUseCaches(true);
hConn.setChunkedStreamingMode(8*1024);
hConn.setDoInput(true);
hConn.setConnectTimeout(60*1000);
hConn.setReadTimeout(60*1000);
hConn.connect();
InputStream bmpIs = hConn.getInputStream();
BufferedInputStream bmpBis = new BufferedInputStream(bmpIs);
Bitmap bmpThumb = null;
BitmapFactory.Options bfOpt = new BitmapFactory.Options();
bfOpt.inScaled = true;
bfOpt.inSampleSize = 2;
bfOpt.inPurgeable = true;
bmpThumb = BitmapFactory.decodeStream(bmpBis,null,bfOpt);
if(bmpThumb == null)
{
for(int i=0; i<10; i++)
{
Thread.sleep(200);
System.gc();
bmpThumb = BitmapFactory.decodeStream(bmpBis,null,bfOpt);
if(bmpThumb == null)
bfOpt.inSampleSize += 1;
else
break;
}
}
I had the exact same problem when trying to decode an image from a byte array. After some experimentation, the solution appears to be to assign some temp storage in the Options of the BitmapFactory. Try:
Options options = new Options();
options.inTempStorage = new byte[256];
Bitmap newMapBitmap = BitmapFactory.decodeStream(instream, null, options);
If the problem is not resolved straight away, try increasing the size of the temp array. I think large bitmap files need a larger buffer for decoding.
HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(url);
} catch (Exception e) {
e.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
Bitmap bm = BitmapFactory.decodeStream(instream);
I experience this error “SkImageDecoder::Factory returned null” about 1 out of 8 times, even if I download the entire file to a buffer, then decode the byte array to a bitmap. I tried the following and none worked for me:
I don’t believe the flushed input stream workaround would work either. It does appear to be an Android skia bug. People are still reporting problems here: http://code.google.com/p/android/issues/detail?id=6066. I have no workaround for this bug except to retry if the bitmap is null, which only reduces the chances of getting the error.