转换输入流中的位图位图

2023-09-03 23:00:31 作者:-染勒头发,换勒面。

我从网上转换输入流中的位图的问题。问题只发生在输入图像类型为.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
 
在cdr中转换一下位图保存怎么会显示导出,保存出现两个文件呢

这似乎是一个共同的问题。做了搜索,我发现一个解决方案。

我的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(河道);
 

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);

Source