I have a bunch of images from a dozen sources, and I upload them to the background stream. Most images load without problems, but there are 2 sources that cause problems. All images from them are not loaded.
I use the following code to upload (and store) images:
File f=new File(cacheDir, urlHash);
Bitmap bitmap=null;
InputStream is=new URL(url).openStream();
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
bitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, null);
Utils.CopyStream:
public static void CopyStream(InputStream is, OutputStream os)
{
int counter = 0;
final int buffer_size=1024;
try
{
byte[] bytes=new byte[buffer_size];
for(;;)
{
int count=is.read(bytes, 0, buffer_size);
if(count==-1) {
Log.d("tag", counter + " bytes copied");
break;
}
os.write(bytes, 0, count);
counter += count;
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
http://www.zapakatel.cz/static/deal/7193-1057b.jpg, . BitmapFactory.decodeStream NULL. , , : is.bytesRemaining : 162721 179845 . URL- , .
, ? , , , ? iphone ( , , , , )