Java: Additional Code Builder (Picture)

xiaoxiao2021-03-06  14

[Picture.java] package creator.comMon.attachlogin; import java.io. *; Public class picture {final int key = 1; final string error_format_int = "format of color is not rgb.sample /" 212 | 232 | 0 / ""; Final string error_color_input = "format of color (num): Num in 0-255"; / ** Format Output Data ** / public string management {String returnstr = " Temp = encrypt (Temp); byte [] by = Temp.getbytes (); for (int i = 0; i - 1) {len ; first = i 1;} Byte [] by = new byte [len]; first = 0; while ((i = temp.indexof ("|", first ))> - 1) {by [index] = byte.parsebyte (timp.substring (first, i)); index ; first = i 1;} returnity by;} / ** Randomly generate four additional code * * / Public string getrandom () {Int i1 = (int) (java.lang.math.random () * 10); int I2 = (int) (java.lang.math.random () * 10); int i 3 = (int) (java.lang.math.random () * 10); INT i4 = (int) (java.lang.math.random () * 10); Return String.Valueof (i1) String.Valueof (i2) String.Valueof (i3) String.Valueof (i4);} / ** encryption 1: misalignment processing ** / public string encrypt (String Randomstr) {String Para = random () randomstr.substring (0 , 1) Random () random () randomstr.substring (1, 2); Para = Para Random () randomstr.substring (2); return jiami (para);} / ** Get random number 0 -9 between ** / private string random () {string Temp =

String.ValueOf ((int) (java.lang.math.random () * 10)); return temp;} / ** encryption 2: Encryption processing, this method can modify ** / private string jiami (String STR) {Byte [] by = str.getbytes (); byterrayinputstream in = new byterrayinputstream (by); int ch; int index = 0; byte [] temp = new byte [in.available ()]; while ((ch = in) .read ()) = - 1)! {temp [index] = (byte) (ch-key); index ;} ByteArrayInputStream ins = new ByteArrayInputStream (temp); BufferedReader fReader = new BufferedReader (new InputStreamReader (ins)); Try {returnFReader.readLine ();} Catch (Exception E) {return "";}} / ** Get the correct number from the number ** / public string discrypt (String Temp) {String Para = JIEMI Dismanage (TEMP)); return para.substring (1, 2) Para.Substring (4, 5) Para.Substring (6, 8);} / ** Decryption Processing ** / Private String Jiemi (Byte [] BYTEARRAYINPUTSTREAM IN = New ByteArrayinputStream (by); int CH; int index = 0; byte [] temp = new byte [in.available ()]; while ((ch = in.read ())! = - 1 ) {TEMP [INDEX] = (Byte) (CH Key); i ndex ;} ByteArrayInputStream ins = new ByteArrayInputStream (temp); BufferedReader fReader = new BufferedReader (new InputStreamReader (ins)); try {return fReader.readLine ();} catch (Exception e) {return "";}} / ** Decompose RGB format color NUM | NUM | NUM ** / Public INT [] masterdata (String Temp) {INDEX = 0, Next_Index = 0; int [] return_arr = new int [3]; boolean break_error = False; if (getmax (Temp, "|") == 2) {while ((index_len = temp.indexof ("|", next_index))> - 1) {if (getInt (NEMP.SUBSTRING (NEXT_INDEX, INDEX_LEN) ) ==

256) {break_error = true;} else {return_arr [index] = getInt (temp.substring (next_index, index_len)); next_index = index_len 1; index ;} if (break_error) break;} if (break_error) {return null ;} else {return_arr [index] = getInt (temp.substring (next_index)); return return_arr;}} else {System.out.println (error_format_int ":" temp); return null;}} private int getMax (String temp, String temp2) {int index = 0, index_len = 0, index_next = 0; while ((index = temp.indexOf (temp2, index_next))> - 1) {index_len ; index_next = index 1;} return index_len; } private int getInt (String temp) {try {return Integer.parseInt (temp);} catch (Exception e) {System.out.println (error_color_input ":" temp); return 256;}}} [CreateImage.java Package Creator.comMon.attachlogin; import java.io. *; Import javax.servlet. *; Import javax.servlet.http. *; Import java.awt. *; Import j ava.awt.image *;. import java.awt.image.BufferedImage; import com.sun.image.codec.jpeg *;. import com.sun.image.codec.jpeg.JPEGCodec; public class CreateImage extends HttpServlet {static final private String CONTENT_TYPE = "text / html; charset = gb2312"; final String input_back_color_error = "input rgb backcolor is error"; final String input_fore_color_error = "input rgb forecolor is error"; private Picture pic = new Picture ();

// Initialize global variables public void init () throws ServletException {} // Process the HTTP Get request public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// generate picture try {int imageWidth = 60; int imageHeight = 20; BufferedImage image = new BufferedImage (imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics graphics = image.getGraphics (); graphics.setColor (Color.white); graphics.fillRect (0,0, imageWidth, imageHeight); graphics. setColor (Color.white); FileOutputStream fos = new FileOutputStream ( "attach.jpg"); BufferedOutputStream bos = new BufferedOutputStream (fos); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (bos); encoder.encode (image); bos.close ( );} Catch (exception e) {system.out.println ("Generated Picture Error!");} String querynum = Request.getParameter ("image"); string queryRGB = ""; if (Request.GetParameter ("RGB ")! = null) {qu eryRgb = request.getParameter ( "Rgb");} response.setHeader ( "Cache-Control", "no-store"); response.setContentType ( "image / jpeg"); ServletOutputStream out = response.getOutputStream (); / / background color picture jpg format (the same as in the page style), 3.6 mm wide, 1.8 mm high InputStream imageIn = new FileInputStream (new File ( "attach.jpg")); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder (imageIn); BufferedImage image4 = decoder.decodeasbufferedImage (); querynum = pic.discrypt (querynum); graphics g = image4.getgraphics (); if (queryrgb.length ()>

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

New Post(0)