图像无法解码

时间:2016-04-04 11:39:47

标签: android bitmapfactory

enter image description here

我将此图像作为字节数组获取。所以我编码bytearray并将其存储在db中。稍后解码此字节数组并将其保存在SD卡中。问题是,我无法将此图像加载到图像视图中。它告诉,skia - >解码器解码错误。 bytearray无法转换为位图。这是我用来将bytearray转换为位图的代码

事实上,甚至无法在Android设备中的Imagebrowser中打开图像(我也在Es Image浏览器中尝试过)。但是,如果我使用Chrome浏览器或HTML查看器打开此图像,它将完美打开。

byte[] byteArray= android.util.Base64.decode(in.getBytes(), android.util.Base64.DEFAULT);
        if (byteArray != null) {
            Log.d(Utilities.class.getSimpleName(), byteArray.toString() + "byteArray Length-->" + byteArray.length);
        } else {
            Log.d(Utilities.class.getSimpleName(), "byteArray is null");
        }
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

编码代码:

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream is = null;
        try {
            is = conn.getInputStream();
            byte[] byteChunk = new byte[4096]; // Or whatever size you want to read in at a time.
            int n;

            while ( (n = is.read(byteChunk)) > 0 ) {
                baos.write(byteChunk, 0, n);
            }
        }
        catch (IOException e) {
            System.err.printf ("Failed while reading bytes from %s: %s", url.toExternalForm(), e.getMessage());
            e.printStackTrace ();
            // Perform any other exception handling that's appropriate.
        }
        finally {
            if (is != null) { is.close(); }
        }
        response.append(Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT));

这是我得到的base64字符串

Base64 string of image

任何人都可以帮我解决这个问题。

0 个答案:

没有答案
相关问题