I have a really interesting problem:
I get a static google map image with a url like this .
I tried several ways to get this information: Getting the "remote resource" as ByteArrayOutputStream, saving the image in the SD simulator, etc. ... but every freaking time I get an IlegalArgumentException .
I always get a 200 http response and the correct MIME type ("image / png"), but in any case: extracting the image and converting it to a bitmap image or saving the image to SD and reading it later; I get the same result ... the file is always corrupted.
I really believe in his coding problem or reading method (similar to this):
public static Bitmap downloadImage(InputStream inStream){
byte[] buffer = new byte[256];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (inStream.read(buffer) != -1){
baos.write(buffer);
}
baos.flush();
baos.close();
byte[] imageData = baos.toByteArray();
Bitmap bi = Bitmap.createBitmapFromBytes(imageData, 0, imageData.length, 1);
return bi;
}
The only thing that comes to mind is imageData.lenght (the answer is content length: 6005), but I really can't figure it out. Any help is more than welcome ...
source
share