Java打印文字点阵信息

来源:互联网 发布:南风知我意1txt书包网 编辑:程序博客网 时间:2024/06/05 03:15

输出文字到图片, 读取图片像素, 打印.



public class Hello{    public static void main(String[] args)    {        BufferedImage image = new BufferedImage(200, 200,                BufferedImage.TYPE_INT_ARGB);        Graphics2D g = image.createGraphics();        g.setFont(new Font("华文彩云", Font.BOLD, 60));        g.setColor(new Color(0xfeab0899));        g.drawString("我爱你", 2, image.getHeight() - 20);        int[] p = image.getRGB(0, 0, image.getWidth(), image.getHeight(),                new int[image.getWidth() * image.getHeight()], 0,                image.getWidth());        char[] cs = {'我', '爱', '你'};        int ics = 0;        for (int i = 0; i < image.getHeight(); i++)        {            for (int j = 0; j < image.getWidth(); j++)            {                int off = i * image.getWidth() + j;                if (p[off] != 0)                {                    System.out.print(cs[ics]);                    ics = (ics + 1) % 3;                } else                {                    System.out.print(" ");                }                if (j == image.getWidth() -1 )                {                    System.out.println();                }            }        }    }}


0 0
原创粉丝点击