1. Reason
This error occurs because the image format is incomplete or the image format stored in the interface conflicts with the internal encoding.
2. Solve
Convert it to png and then call Tesseract
I packaged a tool
// Convert the image to png format 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; }
You cannot directly change the suffix, you need to use ImageIO to convert it, remember
Read More:
- Java learning unreported exception java.io.IOException ; must be caught or declared to be thrown
- Error: char cannot be dereferenced [How to Solve]
- [Solved] Execution failed for task ‘:app:uploadCrashlyticsMappingFileRelease‘
- [Solved] android Execution failed for task ‘:app:processDebugManifest‘
- Java parsing xml file encounters special symbols & will be abnormal solutions
- [Solved] Java.util.linkedhashmap cannot be cast to entity class
- [Solved] IDEA jsp File Error: pageContext.setAttribute(“APP_PATH“,request.getContextPath());
- Java error prompt….. cannot be resolved
- [Solved] o2o Error: addShopImg error:null / character to be escaped is missing
- Jtextfield cannot be displayed normally when added to JPanel
- Tensorflow Error TypeError: Fetch argument XXXX has invalid typeXXXX,must be a string or Tensor
- [Javac compilation exception] javac compilation prompts that the package in jdk cannot be found error: package jdk.internal.org.objectweb.asm does not exist and error: cannot find symbol
- [Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty
- The java springboot websocket service server actively closes the connection and causes java.io.EOFException to be thrown
- [Solved] Could not find resource COM / atguigu / Dao / studentdao.xm, the mapper file for storing SQL statements could not be found and an error occurred
- [Solved] The war package Error: The reason why the XSD file could not be found
- [Solved] IDEA plug-in jrbel hot deployment cannot be started error
- Eclipse Error: There are no resources that can be added or removed from the server.
- [How to Solve]Repeated column in mapping for entity,should be mapped with insert=“false“ update=“false“