Here is the specific code:
Package com.jinzhi.tes2;
Import Java.awt.Color;
Import Java.awt.Font;
Import Java.awt.Graphics;
Import Java.awt.Graphics2D;
Import Java.awt.image.BufferedImage;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Javax.imageio.ImageIO;
Use Java classes to draw a simple QR code
public class Imgdemo {
public static void Main (string[] args) {
Image-related classes image, ImageIO, BufferedImage, Icon, ImageIcon
CAPTCHA Action: Login: Prevent duplicate commit
Construct picture buffers-picture frames
BufferedImage bi = new BufferedImage (+, +, BUFFEREDIMAGE.TYPE_INT_RGB);
Get the Paint pen-brushes (get brushes from the picture frame)
graphics2d g2 = (graphics2d) bi.getgraphics ();
Fills a rectangle
G2.setcolor (Color.White);//
G2.filloval (0, 0, 150, 70);//starting from 0, 0 all fills set the background to white
G2.setfont (New Font ("italics", Font.Bold, 18));
G2.setcolor (Color.Black);//Set Font color
Write a string to a picture
G2.drawstring ("Mama", 15, 25);
try {
Imageio.write (BI, "JPEG", New FileOutputStream ("e:/a.jpg"));
} catch (FileNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
Draw a simple verification code in Java