⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leadbbsnewvalidcode.java

📁 图片识别程序,得到图象的长度和宽度,得到验证码
💻 JAVA
字号:
import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.net.URL;import javax.imageio.ImageIO;public class LeadbbsNewValidCode {                private int intImgWidth;                private int intImgHeight;                private BufferedImage img;                String[] number = new String[]{                                "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,1,0,1,1,0,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,",                                "1,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,",                                "0,1,1,0,0,0,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,1,1,0,0,0,1,0,1,1,0,0,0,1,1,",                                "0,1,0,0,0,0,1,0,1,1,0,0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,",                                "0,0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,0,1,",                                "1,1,1,1,0,0,1,0,1,1,1,1,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,1,0,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,0,",                                "0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,1,0,1,0,0,0,1,1,1,0,1,1,1,1,1,0,0,0,1,1,1,1,1,",                                "1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,",                                "0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,",                                "0,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,"                };                /**                 * 构造函数                 *                 * @param url                 *                                                                                                                                                                                  远程文件                 * @throws IOException                 */                public LeadbbsNewValidCode(URL url) throws IOException {                                img = ImageIO.read(url);                                // 得到图象的长度和宽度                                intImgWidth = img.getWidth();                                intImgHeight = img.getHeight();                }                /**                 * 构造函数                 *                 * @param file                 *                                                                                                                                                                                  本地文件                 * @throws IOException                 */                public LeadbbsNewValidCode(File file) throws IOException {                                img = ImageIO.read(file);                                // 得到图象的长度和宽度                                intImgWidth = img.getWidth();                                intImgHeight = img.getHeight();                }                /**                 * 得到验证码                 *                 * @return                 */                public String getImgStr() {                                int i = 0;                                String numberString = "";                                String str = "";                                for (int x = 2; x < intImgWidth - 3; x++) {                                                i += 1;                                                for (int y = 1; y < intImgHeight - 3; y++) {                                                                if (i % 7 != 0) {                                                                                if (img.getRGB(x, y) < -1000000) {                                                                                                str += "1,";                                                                                } else {                                                                                                str += "0,";                                                                                }                                                                } else {//                                                                                System.out.println(str);                                                                                numberString += searchNumber(str);                                                                                str = "";                                                                }                                                }                                }                                numberString += searchNumber(str);                                return numberString;                }                /**                 * 数字匹配                 *                 * @param imgStr                 * @return                 */                public String searchNumber(String imgStr) {                                if (imgStr == null || imgStr.equals("")) {                                                return "";                                }                                String strNumber = "";                                String[] imgStrArray = imgStr.split("\\,");                                int iRight = 0;                                String returnValue = "";                                for (int i = 0; i < number.length; i++) {                                                int forRight = 0;                                                String[] temp = number[i].split("\\,");                                                for(int j = 0; j < temp.length; j++){                                                                if(imgStrArray[j].equals(temp[j])){                                                                                forRight += 1;                                                                }                                                }                                                if(forRight > iRight){                                                                iRight = forRight;                                                                returnValue = "" + i;                                                }                                }                                return returnValue;                }                public static void main(String[] args) {                                try {                                                LeadbbsNewValidCode imageTest = new LeadbbsNewValidCode(new File(                                                                                "c:/number13.jpg"));//                                                 LeadbbsNewValidCode imageTest = new LeadbbsNewValidCode(new URL(//                                                 "http://www.leadbbs.com/User/number.asp?r=1"));                                                System.out.println(imageTest.getImgStr());                                } catch (IOException ex) {                                                System.out.println(ex.getMessage());                                }                }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -