I am creating an Android app and am currently having problems retrieving a bitmap from a URL. Here is the code I'm using:
public static Bitmap bmpFromURL(URL imageURL){
Bitmap result = null;
try {
HttpURLConnection connection = (HttpURLConnection)imageURL .openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
result = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
Everything works fine when the image is being recorded, but when some bytes are erroneous, the result is null. I think this is mostly expected, as it is written in the document BitmapFactory.decodeStream:
If the input stream is null or cannot be used to decode a bitmap, the function returns null. The position of the stream will be where it was after reading the encoded data.
The problem is that my wrong picture is well interpreted by my web browser, and I can do it on the iPhone platform.
? ?