利用JavaFX生成验证码图片
以下是一个基于 JavaFX 的验证码图片生成小程序的示例代码:
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
import java.io.File;
import java.util.Random;
public class CaptchaGenerator extends Application {
private static final int WIDTH = 150;
private static final int HEIGHT = 50;
private static final int FONT_SIZE = 30;
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static final int NUM_CHARACTERS = 4;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Canvas can