Java 安卓-Base64中的海量数据,如何处理

Java 安卓-Base64中的海量数据,如何处理,java,android,json,web-services,base64,Java,Android,Json,Web Services,Base64,我有一个web服务,它给了我一个json,其中有一个名为“imagedata”的节点。它以字符串形式包含大量数据。当我在浏览器中打印时,它会给我有效的输入。Base64编码字符串以“=”字符结尾 我还在一个html页面中使用这个标记对它进行了测试,它工作得非常好 <img src="data:image/png;base64,MY_BASE64_ENCODED_STRING"/> 请注意,此代码适用于较小的图像数据,但在较大的图像数据上会出现bad-base64异常 请帮帮我, 谢

我有一个web服务,它给了我一个json,其中有一个名为“imagedata”的节点。它以字符串形式包含大量数据。当我在浏览器中打印时,它会给我有效的输入。Base64编码字符串以“=”字符结尾

我还在一个html页面中使用这个标记对它进行了测试,它工作得非常好

<img src="data:image/png;base64,MY_BASE64_ENCODED_STRING"/>
请注意,此代码适用于较小的图像数据,但在较大的图像数据上会出现bad-base64异常

请帮帮我,
谢谢

为什么您的服务器给您base64编码?。Base64只是通信,而不是编码图像。如果它用于编码,则会使图像文件大小变大。IllegalArgumentException表示图像编码格式不正确或无法解码。 在我的项目中,我只是暂时使用Base64来发送图像。但它将通过多个部分进行更改。但当服务器转发给收件人时。它只是转发图像的url。因此,我可以用以下方法简单地处理url到图像:

public static Image loadImage(String url)
{
    HttpConnection connection = null;
    DataInputStream dis = null;
    byte[] data = null;

    try
    {
        connection = (HttpConnection) Connector.open(url);
        int length = (int) connection.getLength();
        data = new byte[length];
        dis = new DataInputStream(connection.openInputStream());
        dis.readFully(data);
    }
    catch (Exception e)
    {
        System.out.println("Error LoadImage: " + e.getMessage());
        e.printStackTrace();
    }
    finally
    {
        if (connection != null)
            try
            {
                connection.close();
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        if (dis != null)
            try
            {
                dis.close();
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }


    return Image.createImage(data, 0, data.length);
}

注意J2ME的这段代码。

任何异常stacktrace?都建议使用Base64.decode(dataObj.getString(“imagedata”),0);directly@Stacks28仍然得到相同的错误。java.lang.IllegalArgumentException:bad base-64在后台下载它怎么样(就像在你的浏览器中一样)我已经在AsyncTask@Nizam中这样做了问题是如何将它解码回位图?它只在大的编码字符串中给出异常。
public static Image loadImage(String url)
{
    HttpConnection connection = null;
    DataInputStream dis = null;
    byte[] data = null;

    try
    {
        connection = (HttpConnection) Connector.open(url);
        int length = (int) connection.getLength();
        data = new byte[length];
        dis = new DataInputStream(connection.openInputStream());
        dis.readFully(data);
    }
    catch (Exception e)
    {
        System.out.println("Error LoadImage: " + e.getMessage());
        e.printStackTrace();
    }
    finally
    {
        if (connection != null)
            try
            {
                connection.close();
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        if (dis != null)
            try
            {
                dis.close();
            }
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }


    return Image.createImage(data, 0, data.length);
}