サーバーから画像をダウンロードするためにこのコードを使用しています:
public Bitmap getBitmap(String path){
URL url=new URL(path);
URLConnection connection=url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream is=connection.getInputStream();
Bitmap bmp=BitmapFactory.decodeStream(is);
return bmp;
}
1つの画像では問題なく動作しますが、これをサイクルで使用している場合、2回目、3回目などの反復で奇妙なものを返します(ビットマップmWidth
とmHeight
フィールドは です-1
)。どこに問題がありますか?
(path
2回目、3回目などの繰り返しは問題ありません。これを確認しました)
編集
サイクルの例:
//images - is a String array
for(int i=0; i<images.length(); i++){
Bitmap bmp=getBitmap(images[i]);
}
Ss ご覧のとおり、このサイクルには異常はありません