List of usage examples for java.awt.geom CubicCurve2D setCurve
public abstract void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2);
From source file:business.model.CaptchaModel.java
/** * * @param CaptchaText/*from w w w.j a va 2s .co m*/ * @return */ public static BufferedImage CreateCaptchaImageOld(String CaptchaText) { BufferedImage localBufferedImage = new BufferedImage(width, height, 1); try { Graphics2D localGraphics2D = localBufferedImage.createGraphics(); // List<Font> fonts = FontFactory.getListFont(); List<Font> fonts = new ArrayList<Font>(); if (fonts.isEmpty()) { fonts.add(new Font("Nimbus Roman No9 L", 1, 30)); fonts.add(new Font("VN-NTime", 1, 30)); fonts.add(new Font("DT-Times", 1, 30)); fonts.add(new Font("Times New Roman", 1, 30)); fonts.add(new Font("Vni-Book123", 1, 30)); fonts.add(new Font("VNI-Centur", 1, 30)); fonts.add(new Font("DT-Brookly", 1, 30)); } // fonts.add(loadFont("BINHLBI.TTF")); RenderingHints localRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); localGraphics2D.setRenderingHints(localRenderingHints); localGraphics2D.fillRect(0, 0, width, height); localGraphics2D.setColor(new Color(50, 50, 50)); Random localRandom = new Random(); int i = 0; int j = 0; for (int k = 0; k < CaptchaText.length(); k++) { i += 25 + Math.abs(localRandom.nextInt()) % 5; j = 25 + Math.abs(localRandom.nextInt()) % 20; int tmp = localRandom.nextInt(fonts.size() - 1); localGraphics2D.setFont(fonts.get(tmp)); localGraphics2D.drawChars(CaptchaText.toCharArray(), k, 1, i, j); } localBufferedImage = getDistortedImage(localBufferedImage); Graphics2D localGraphics2D2 = localBufferedImage.createGraphics(); localGraphics2D2.setRenderingHints(localRenderingHints); // localGraphics2D2.fillRect(0, 0, width, height); localGraphics2D2.setColor(new Color(50, 50, 50)); CubicCurve2D c = new CubicCurve2D.Double();// draw QuadCurve2D.Float with set coordinates for (int l = 0; l < 7; l++) { int x1 = Util.rand(0, width / 2); ; int x2 = Util.rand(width / 2, width); int y1 = Util.rand(0, height); int y2 = Util.rand(0, height); int ctrlx1 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly1 = y1; int ctrlx2 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly2 = y2; c.setCurve(x1, y1, ctrlx2, ctrly2, ctrlx1, ctrly1, x2, y2); localGraphics2D2.draw(c); // localGraphics2D2.drawLine(randomX1(), randomY1(), randomX2(), randomY2()); } localGraphics2D.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); return null; } return localBufferedImage; }