urlから画像を読み込んで Bitmapにするコード
こんなコードで 画像ファイルを Bitmapにしていた
public Bitmap bitmapFromUrl(String url) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.connect(); InputStream input = connection.getInputStream(); Bitmap bm = BitmapFactory.decodeStream(input); return bm; }
.pngや .jpgは特に問題なく読み込めていたのだけど、たまたま .icoを読み込んだ時に nullが帰ってきた。
「あれ?」と思ってもう一度やってみると今度は読み込める。
再度試すとまた nullが…。
という具合に読み込めたり読み込めなかったりがランダム(っぽく)続いた。
で、困ってしまったというのが今回の話。