在BlackBerry 5.0中显示静态Google Map图像 [英] Display static Google Map image in BlackBerry 5.0
问题描述
我有一个非常有趣的问题需要解决:
我得到一个静态的Google地图图片,其URL为 this 。
我试过几种方法来获取这些信息:
将远程资源作为ByteArrayOutputStream获取,将图像存储在模拟器的SD中,等等......但每当 freaking 时,我都会收到一个 IlegalArgumentException 。
我总是得到一个200 http响应和正确的MIME类型(image / png),但是无论如何:获取图像并将其转换为位图,或者将图像存储在SD中并稍后阅读;我得到了相同的结果...文件总是损坏。
我真的相信它的一个编码问题,或者读取方法(类似于这个):
p> 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();
位图bi = Bitmap.createBitmapFromBytes(imageData,0,imageData.length,1);
//位图bi = Bitmap.createBitmapFromBytes(imageData,0,-1,1);
返回bi;
}
唯一想到的就是imageData.lenght(在响应中,内容长度是:6005),但我真的无法弄清楚这一点。
任何帮助都比欢迎...
试试这种方式:
InputStream input = httpConn.openInputStream();
byte [] xmlBytes = new byte [256];
int len = 0;
int size = 0;
StringBuffer raw = new StringBuffer();
while(-1!=(len = input.read(xmlBytes)))
{
raw.append(new String(xmlBytes,0,len));
size + = len;
}
value = raw.toString();
byte [] dataArray = value.getBytes();
EncodedImage位图;
bitmap = EncodedImage.createEncodedImage(dataArray,0,dataArray.length);
最终位图googleImage = bitmap.getBitmap();
I'm having a really interesting problem to solve:
I'm getting a static google map image, with an URL like this.
I've tried several methods to get this information: Fetching the "remote resource" as a ByteArrayOutputStream, storing the Image in the SD of the Simulator, an so on... but every freaking time I get an IlegalArgumentException.
I always get a 200 http response, and the correct MIME type ("image/png"), but either way: fetching the image and converting it to a Bitmap, or storing the image in the SD and reading it later; I get the same result... the file IS always corrupt.
I really belive its an encoding problem, or the reading method (similar to this one):
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);
//Bitmap bi = Bitmap.createBitmapFromBytes(imageData, 0, -1, 1);
return bi;
}
The only thing that comes to mind is the imageData.lenght (in the response, the content length is: 6005 ), but I really can't figure this one out. Any help is more than welcome...
try this way:
InputStream input = httpConn.openInputStream();
byte[] xmlBytes = new byte[256];
int len = 0;
int size = 0;
StringBuffer raw = new StringBuffer();
while (-1 != (len = input.read(xmlBytes)))
{
raw.append(new String(xmlBytes, 0, len));
size += len;
}
value = raw.toString();
byte[] dataArray = value.getBytes();
EncodedImage bitmap;
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
final Bitmap googleImage = bitmap.getBitmap();
这篇关于在BlackBerry 5.0中显示静态Google Map图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!