Cat code picture

xiaoxiao2021-03-06  37

/ ** *

Title: check code * *

description: * *

Copyright: CopyRight (c) Karl Luo * *

Company: sfstudio * @Author Karl Luo * @version 1.0 * / import java.io. *; Import java.awt.image. *; Import java.util.hashtable; import com.sun.image.codec .jpeg. *;

public class ValidationImage {private String validationCode = ""; // check code private int validationCodeLength = 6; // check code length private int imWidth = 114; // Image Width private int imHeight = 27; // private String Image Height IMTYPE = "JPEG"; // Picture Type Private String ImfileName = ""; // Generate Image File Name Private BufferedImage Bufimg = NULL; Private Int Wmatrix = 5; // Array Width Private Int Hmatrix = 7; // Array High Private int [] CHAR_1 = {0, 0, 1, 0, 0}, {0, 1, 1, 0, 0}, {0, 0, 1, 0, 0}, {0,0,1 , 0, 0, 1, 0, 0}, {0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}}; private int [] [] char_2 = {{0, 1, 1, 1, 0}, {1,0,0,0,1}, {0, 0, 0, 0, 1}, {0, 0, 1, 1, 0}, {0, 1, 0, 0, 0}, {1, 1, 1, 1, 1}}; private int [] [] char_3 = {{0,1 1, 1, 0}, {1, 0, 0, 0, 1}, {0, 1, 1, 1, 10}, {0,0,0 , 0, 1}, {1, 0, 0, 0, 1}, {0, 1, 1, 1, 0}}; private int [] [] char_4 = {{1,0,0,0,1 }, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 1, 1, 1, 1}, {0, 0, 0, 0, 1}, {0,0,0,0,1}, {0, 0, 0, 0, 1}; private int [] [] char_5 = {{1, 1, 1, 1, 1}, {1,0 , 0, 0, 0}, {1, 0, 0, 0}, {1,1 1, 1, 0}, {0, 0, 0, 0, 1}, {0, 1, 1, 1, 10}}; private int [] [] ] CHAR_6 = {{0, 1, 1, 1, 10}, {1, 0, 0, 0, 1}, {1, 0, 0, 0}, {1, 1, 1, 1, 0 }, {1,0,0,0,1}, {1,0,0,0,1}, {0, 1, 1, 1, 0}}; private int [] [] char_7 = {{1 1, 1, 1, 1}, {1,0,0,0,1}, {0, 0, 0, 1, 0}, {0,0 , 1, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 0, 0}}; private int [] [] char_8 = {{0, 1, 1, 1 , 0}, {1, 0, 0, 1}, {1,0,0,0,1}, {0, 1, 1, 1, 0}, {1,0,0,0,1 }, {1,0,0,0,1}, {0, 1, 1, 1, 0}}; private int [] [] char_9 = {{0, 1, 1, 1, 0}, {1 , 0, 0, 0, 10, 1}, {0, 1, 1, 1, 1}, {0, 0, 0, 0, 1}, {1,0 , 0, 10, 1}, {0, 1, 1, 1, 0}}; private int [] [] char_0 = {{0, 1, 1, 1, 0}, {1,0,0,0 1}, {1, 0, 0, 1, 1}, {1, 10, 1, 0, 1}, {1, 1, 0, 0, 1}, {1, 0, 0, 0, 1 }, {0, 1, 1, 1, 0}};

Private int [] [] char_a = {{0, 1, 1, 1, 10}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1,0, 0, 0, 1}, {1, 1, 1, 1, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}}; private int [] [] CHAR_B = {{1,1,1,1,0}, {1,0,0,0,1}, {1, 1, 1, 1, 10} {1, 0, 0, 0, 1}, {1, 1, 1, 1, 0}}; private int [] [] char_c = {{0, 1, 1, 1, 0}, {1, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, {1, 0, 0, 0, 1}, {0, 1, 1, 1, 0}}; private int [] [] char_d = {{1, 1, 1, 1, 0}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1} , {1, 0, 0, 0, 1}, {1, 1, 1, 1, 0}}; private int [] [] char_e = {{1, 1, 1, 1, 1}, {1, 0, 0, 0, 0}, {1,1,1,1,0}, {1, 0, 0, 0, 0}, {1,0, 0,0,0}, {1, 1, 1, 1, 1}; private int [] [] char_f = {1, 1, 1, 1, 1}, {1, 0, 0, 0, 0}, {1,0,0,0}, {1, 1, 1, 1, 0}, {1, 0, 0, 0}, {1, 0, 0, 0, 0} , {1, 0, 0, 0, 0}; private int [] [] char_g = {{0, 1, 1, 1, 0}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 0}, {1, 0, 1, 1, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {0, 1, 1, 1, 0}}; private int [] [] char_h = {{1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 1, 1, 1, 1}, {1, 0, 0, 0, 1}, {1,0,0,0,1}, {1,0,0,0,1} }; Private int [] [] char_i = {{1, 1, 1, 1, 1}, {0, 0, 1, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 0, 0}, {1, 1, 1, 1, 1}}; private int [] [] char_j = {{0, 0, 0, 0, 1}, {0, 0, 0, 0, 1}, {0, 0, 0, 0, 1}, {0,0,0,0,1}, {0, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {0, 1, 1, 1, 0} }; Private int [] [] char_k = {{1, 0, 0, 0, 1}, {1, 0, 0, 1, 0}, {1, 0, 1, 0, 0}, {1, 1, 0, 0, 0}, {1,0,0,1,0}, {1, 0, 0, 0, 1}}; private int [] [] CHAR_L = {{1, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, {1,0,0,0, 0}, {1, 0, 0, 0, 0}, {1, 0, 0, 0}, {1, 1, 1, 1, 1}}; private int [] [] char_m = {{{ 1, 0, 0, 0, 1}, {1,0,1,0,1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1,0,0,0,1}}; private int [] [] char_n = {{1,0,0, 0, 1}, {1, 1, 0, 0, 1}, {1, 0, 1, 0, 1}, {1, 0, 0, 1, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}}; private int [] [] char_o =

{{0, 1, 1, 1, 0}, {1,0,0,0,1}, {1,0,0,0,1}, { 1, 0, 0, 0, 1}, {0, 1, 1, 1, 10}; private int [] [] char_p = {{1, 1, 1, 1, 0}, {1,0,0,0,1}, {1, 1, 1, 1, 0}, {1,0,0, 0,0}, {1, 0, 0, 0}, {1, 0, 0, 0}}; private int [] [] char_q = {{0, 1, 1, 1, 0} {1,0,0,0,1}, {1,0,0,0,1}, {1, 0, 0, 0, 1}, { 1, 0, 0, 1, 1}, {0, 1, 1, 1, 1}}; private int [] [] char_r = {{1, 1, 1, 1, 0}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1,0,0,0,1}, {1,0,0, 0, 1}, {1, 0, 0, 0, 1}; private int [] [] char_s = {{0, 1, 1, 1, 0}, {1,0,0,0,1} {1,0,0,0}, {0, 1, 1, 1, 0}, {0, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, { 0, 1, 1, 1, 0}}; private int [] [] char_t = {{1, 1, 1, 1, 1}, {0, 0, 1, 0, 0}, {0, 0, 1,0,0}, {0, 0, 1, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 0,0}}; private int [] [] char_u = {{1,0,0,0,1}, {1, 0, 0, 0, 1}, {1,0,0,0,1} {1,0,0,0,1}, {1,0,0,0,1}, {0, 1, 1, 1, 0}}; Private int [] [] CHAR_V = {{1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}, {0, 1, 0, 1, 0}, {0, 1, 0, 1, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 0, 0}}; private int [] [] CHAR_W = {{1,0,0,0,1}, {1,0,0,0,1}, {1,0,0,0,1} , {1,0,1, 0, 1}, {1, 0, 1, 0, 1}, {0, 1, 0, 1, 0}}; private int [] [] char_x = {{1,0,0,0,1} {1,0,0,0,0}, {0, 1, 1, 0, 0}, {0, 1, 0, 1, 0}, { 1, 0, 0, 0, 1}, {1, 0, 0, 0, 1}}; private int [] [] char_y = {{1, 0, 0, 0, 1}, {1,0, 0, 0, 1}, {0, 1, 0, 1, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 0,0}, {0, 0, 1, 0, 0}; private int [] [] char_z = {{1, 1, 1, 1, 1}, {0, 0, 0, 0, 1} {0,0,0,0,0}, {0, 1, 0, 0, 0}, {1, 0, 0, 0, 0}, { 1, 1, 1, 1, 1}};

private Hashtable charMatrixTable = null; / ** * initialize character array stored in the hash table * / private void InitCharMatrix () {charMatrixTable = new Hashtable ();! charMatrixTable.put ( "1", char_1); charMatrixTable.put ( "2", char_2); charmatrixtable.put ("3", char_3); CharmatrixTable.Put ("4", char_4); CharmatrixTable.Put ("5", char_5); CharmatrixTable.Put ("6", char_6) CharmatrixTable.Put ("7", Char_7); CharmatrixTable.Put ("8", Char_8); CharmatrixTable.Put ("9", Char_9); CharmatrixTable.Put ("0", CHAR_0);

CharmatrixTable.Put ("a", char_a); charmatrixtable.put ("b", char_b); charmatrixtable.put ("c", char_c); charmatrixtable.put ("d", char_d); charmatrixtable.put ("e ", char_e); charmatrixtable.put (" f ", char_f); charmatrixtable.put (" g ", char_g); charmatrixtable.put (" h ", char_h); charmatrixtable.put (" i ", char_i); charmatrixtable .put ("j", char_j); CharmatrixTable.Put ("k", char_k); charmatrixtable.put ("l", char_l); charmatrixtable.put ("m", char_m); charmatrixtable.put ("n" CHAR_N); CharmatrixTable.Put ("O", char_o); CharmatrixTable.Put ("P", char_p); CharmatrixTable.Put ("Q", char_q); CharmatrixTable.Put ("R", CHAR_R); CharmatrixTable. PUT ("s", char_s); charmatrixtable.put ("t", char_t); charmatrixtable.put ("u", char_u); charmatrixtable.put ("v", char_v); charmatrixtable.put ("w", Char_w); CharmatrixTable.Put ("x", char_x); charmatrixtable.put ("y", char_y); charmatrixtable.put ("z", char_z);} / ** * Construction function * / Public ValidationImage (String imFileName) {this.validationCode = this.GetNewValidationCode (); this.imFileName = imFileName; this.Init ();} / ** * constructor * @param validationCode String * / public ValidationImage (String validationCode, String imfilename) {this.validationcode = validationcode; this.imfilename = imfilename; this.init ();

/ ** * Initialization * / private vidinit () {Try {this.initcharmatrix (); this.getnewImage (); this.drawvalidationcode (); this.outputImage (this.imfilename);} catch (Exception E) {system .out.println ("error");}} / ** * Generate a check code, not implemented, implemented by the PHP program * @return string * / private string getNewValidationcode () {Return "JDK142";} / ** * Create Image * @return boolean * / private void getNewImage () {this.bufImg = new BufferedImage (this.imWidth, this.imHeight, BufferedImage.TYPE_3BYTE_BGR);} / ** * characters obtained according to the bitmap * @return int [ ] [] * / Private int [] [] getcharmatrix (char c) {int [] [] cm = (int [] []) this.charmatrixtable.get (String.Valueof (c)); return cm;} / ** * Picture Code to Picture * * / Private Void DrawValidationCode () {if ((this.validationcode == ") || (this.bufimg == null) {return;} int [] RGBarra Y = {-1, -1, -1}; for (int i = 0; i

IF (cm [j] [k] == 1) {bufimg.setrGB (XIMG, YIMG, 2, 2, RGBARRAY, 0, 0);}

转载请注明原文地址:https://www.9cbs.com/read-59750.html

New Post(0)