转换输入流中的位图 [英] Converting input stream into bitmap
问题描述
我从网上转换输入流中的位图的问题。问题只发生在输入图像类型为.BMP(位图)。在这种情况下: bitmapFactory.de codeStream返回null 。
任何提示如何解决这个问题,或者我应该继续我的调试?
平台:Android的(蜂窝)
的URLConnection康恩= url.openConnection();
conn.connect();
的InputStream = conn.getInputStream();
的BufferedInputStream =新的BufferedInputStream(InputStream的);
BMP = BitmapFactory.de codeStream(的BufferedInputStream);
感谢您@Amir的点出日志。发现了一个行:
德codeR->德code返回false
这似乎是一个共同的问题。做了搜索,我发现一个解决方案。
我的previous code:
的URLConnection康恩= url.openConnection();
conn.connect();
的InputStream = conn.getInputStream();
的BufferedInputStream =新的BufferedInputStream(InputStream的);
BMP = BitmapFactory.de codeStream(的BufferedInputStream);
code这是工作的:
HTTPGET HTT prequest = NULL;
尝试 {
HTT prequest =新HTTPGET(url.toURI());
}赶上(的URISyntaxException E){
e.printStackTrace();
}
HttpClient的HttpClient的=新DefaultHttpClient();
HTT presponse响应=(HTT presponse)httpclient.execute(HTT prequest);
HttpEntity实体= response.getEntity();
BufferedHttpEntity bufHttpEntity =新BufferedHttpEntity(实体);
InputStream的河道= bufHttpEntity.getContent();
BMP = BitmapFactory.de codeStream(河道);
<一个href="http://groups.google.com/group/android-developers/browse_thread/thread/10a3821158f17be1">Source
I have problems converting a input stream from web into bitmap. Problem occurs only when input image type is .BMP (bitmap). In that case: bitmapFactory.decodeStream returns null.
Any hints how to fix this problem or where should I continue my debugging?
Platform: Android (Honeycomb)
URLConnection conn = url.openConnection();
conn.connect();
inputStream = conn.getInputStream();
bufferedInputStream = new BufferedInputStream(inputStream);
bmp = BitmapFactory.decodeStream(bufferedInputStream);
Thank you @Amir for point out the log. Discovered a line:
decoder->decode returned false
This seems to be a common problem. Doing a search I found a solution.
My previous code:
URLConnection conn = url.openConnection();
conn.connect();
inputStream = conn.getInputStream();
bufferedInputStream = new BufferedInputStream(inputStream);
bmp = BitmapFactory.decodeStream(bufferedInputStream);
Code which is working:
HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
bmp = BitmapFactory.decodeStream(instream);
这篇关于转换输入流中的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!