gpt4 book ai didi

java - 将输入流转换为位图

转载 作者:IT老高 更新时间:2023-10-28 20:45:25 25 4
gpt4 key购买 nike

我在将输入流从 Web 转换为位图时遇到问题。仅当输入图像类型为 .BMP(位图)时才会出现问题。在这种情况下:bitmapFactory.decodeStream 返回 null

任何提示如何解决此问题或我应该在哪里继续调试?

平台:Android(蜂窝)

URLConnection conn = url.openConnection();
conn.connect();

inputStream = conn.getInputStream();

bufferedInputStream = new BufferedInputStream(inputStream);

bmp = BitmapFactory.decodeStream(bufferedInputStream);

最佳答案

感谢@Amir 指出日志。发现一行:

decoder->decode returned false

这似乎是一个常见问题。搜索了一下,找到了解决办法。

我之前的代码:

URLConnection conn = url.openConnection();
conn.connect();

inputStream = conn.getInputStream();

bufferedInputStream = new BufferedInputStream(inputStream);

bmp = BitmapFactory.decodeStream(bufferedInputStream);

正在运行的代码:

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

关于java - 将输入流转换为位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6612263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com