编程语言
首页 > 编程语言> > Tesseract -ocr - java - 报错JFIF APP0 must be first marker after SOI 解决

Tesseract -ocr - java - 报错JFIF APP0 must be first marker after SOI 解决

作者:互联网

1.原因

出现这个报错,是因为图片格式有残缺或者图片格式在接口获取后存储的格式与内部的编码有冲突导致

2.解决

将其转为png后再调用 Tesseract  即可

我封装了个工具

 //转换图片为png格式
    public static String convertPng(String url) {
        String tarFilePath = url.substring(0, url.lastIndexOf(".")) + ".png";
        try {
            BufferedImage bufferedImage = ImageIO.read(new File(url));
            BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
            newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.white, null);
            ImageIO.write(newBufferedImage, "png", new File(tarFilePath));
        } catch (IOException e) {
           return "";
        }
        return tarFilePath;
    }

不可直接改后缀,需要使用 ImageIO 来转才可以, 切记

 

标签:JFIF,ImageIO,String,url,bufferedImage,BufferedImage,报错,Tesseract,png
来源: https://www.cnblogs.com/c2g5201314/p/16673825.html