圣诞节要到了,作为程序员当然要用代码来庆祝一下~
先看看效果图:
废话不多说,直接上代码:
BufferedImage image = new BufferedImage(150, 40, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setFont(new Font("华文新魏", Font.BOLD, 20));
g.drawString("圣诞快乐", 2, image.getHeight() - 10);
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) % 4;
} else {
System.out.print(" ");
}
if (j == image.getWidth() - 1) {
System.out.println();
}
}
}