有个问题请教一下大家,求大神解决
登录页面中的那个验证码怎么编码啊,是个按钮吗?如果不是,那是什么啊?
import java.awt.image.BufferedImage; import import import import java.util.HashMap; import java.util.Map; import java.util.Random; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; public class ImageUtils { private static String str = "1234567890QWERTYUIOPASDFGHJKLZXCVBNM"; private static char[] chars = str.toCharArray(); private static int WIDTH = 140; private static int HEIGHT = 40; private static int SIZE = 4; private static int LINES = 6; private static int FONT_SIZE = 40; public static Map<String, BufferedImage> getImage() { BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics g = image.createGraphics(); g.setColor(Color.GRAY); g.fillRect(0, 0, WIDTH, HEIGHT); StringBuffer bf = new StringBuffer(); Random r = new Random(); for (int i = 0; i < SIZE; i++) { char c = chars[r.nextInt(chars.length)]; g.setColor(getColor()); g.setFont(new Font(null,Font.BOLD,FONT_SIZE)); g.drawString("" + c, i * WIDTH / SIZE, HEIGHT / 10 * 9); bf.append(c); } for (int i = 0; i < LINES; i++) { g.setColor(getColor()); g.drawLine(r.nextInt(WIDTH), r.nextInt(HEIGHT), r.nextInt(WIDTH), r.nextInt(HEIGHT)); } Map<String, BufferedImage> map = new HashMap<String, BufferedImage>(); map.put(bf.toString(), image); return map; } private static Color getColor() { Random r = new Random(); return new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)); } public static InputStream imageToStream(BufferedImage image) throws Exception{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos); encoder.encode(image); byte[] bytes = bos.toByteArray(); InputStream is = new ByteArrayInputStream(bytes); return is; } }这段代码能可以生成验证码,希望可以帮你