图片验证码

 
package com.图片验证码;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class 图片验证码 {
    public static void main(String[] args) throws Exception, IOException {
        //创建一张图片,设置图片大小、类型
        /**
         * BufferedImage(int width, int height, int imageType) 
         * width - 所创建图像的宽度
         * height - 所创建图像的高度
         * imageType - 所创建图像的类型
         */
        BufferedImage bufferedImage = new BufferedImage(50, 50, BufferedImage.TYPE_INT_BGR);
        //得到图片的画笔
        Graphics2D graphics2d = (Graphics2D) bufferedImage.getGraphics();
        //设置图片的背景颜色
        graphics2d.setColor(Color.white);
        //设置图片的背景颜色填充大小
        graphics2d.fillRect(0, 0, 50, 50);
        //设置文字字体,样式,字号
        graphics2d.setFont(new Font("宋体", Font.BOLD, 10));
        //设置文字颜色
        graphics2d.setColor(Color.black);
        //设置文字内容,放置位置   drawString(String str, int x, int y) 
        graphics2d.drawString("张国华",10,20);
        //输出图片到本地
        ImageIO.write(bufferedImage, "jpeg", new FileOutputStream("f:/a.jpg"));
    }
    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值