BitmapFactory.de codeStream(InputStream的)总是返回空当一些字节是错误的 [英] BitmapFactory.decodeStream(inputStream) always return null when some bytes are wrong

查看:92
本文介绍了BitmapFactory.de codeStream(InputStream的)总是返回空当一些字节是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个Android应用程序,我现在遇到了麻烦,从一个网址检索位图。这里是code我使用:

I'm building an android app and I'm currently having trouble retrieving a bitmap from an URL. Here is the code I'm using :

public static Bitmap bmpFromURL(URL imageURL){

    Bitmap result = null;

    try {

        HttpURLConnection connection = (HttpURLConnection)imageURL .openConnection();

        connection.setDoInput(true);

        connection.connect();

        InputStream input = connection.getInputStream();

        result = BitmapFactory.decodeStream(input);


    } catch (IOException e) {


        e.printStackTrace();

    }

    return result;

}

一切工作正常时,图片的写入,但是当一些字节是错误的,结果得到空。我觉得它基本上是可预期的,因为它是这样写的的文档 BitmapFactory.de codeStream

如果输入流为空,或者不能用脱codeA位图,该函数返回null。该流的位置将在以往这是EN codeD数据之后被读取。

If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.

现在的问题是,我错了图片是由我的网络浏览器以及PTED除$ P $,我可以在iPhone平台上做到这一点。

The problem is, my wrong picture is well interpreted by my web browser and I can do so on iPhone platform.

有没有一种方法排序的忽略这些错像素?可能的选项参数?

Is there a way to sort of ignore those wrong pixels? maybe with the option parameter?

pciated任何帮助AP $ P $

Any help appreciated

罗曼

推荐答案

这是一个已知的bug修复Android系统的未来版本。你可以解决它通过首先复制的InputStream的内容转换成一个byte []数组,然后字节数组本身进行解码。

This is a known bug fixed in a future version of Android. You can work around it by first copying the content of the InputStream into a byte[] array and then decoding the byte array itself.

这篇关于BitmapFactory.de codeStream(InputStream的)总是返回空当一些字节是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆