Draw a simple verification code in Java

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.