?? leadbbsnewvalidcode.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 + -