善哉尚在 2016-02-04 08:26 采纳率: 75%
浏览 4207
已采纳

ImageIo.read() 返回null

具体代码如下:
imgStr是一个base64字符串
public static String decoderQRCodeForBase64(String imgStr) throws Exception {
if (imgStr == null) {
return "";
}

    BASE64Decoder decoder = new BASE64Decoder();
    byte[] b = decoder.decodeBuffer(imgStr);
    for (int i = 0; i < b.length; ++i) {
        if (b[i] < 0) {// 调整异常数据
            b[i] += 256;
        }
    }

    InputStream input = new ByteArrayInputStream(b);

    String content = decoderQRCode(input);

    return content;

}


public static String decoderQRCode(InputStream input) throws Exception {
    BufferedImage bufImg = null;
    String content = null;

    bufImg = ImageIO.read(input);
    QRCodeDecoder decoder = new QRCodeDecoder();
    content = new String(decoder.decode(new TwoDimensionCodeImage(bufImg)),
            "utf-8");

    return content;
}

在bufImg = ImageIO.read(input);这里读不出来,返回的是null,为什么呢,求大神解答,小白在线等。
  • 写回答

4条回答

  • 毕小宝 博客专家认证 2016-02-04 10:50
    关注

    捕获下异常,看看运行时有没有异常信息。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable