该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package com.strong;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class JavaZiMo {
private static int intKuan = 64;
private static int intGao = 64;
private static int intSuoFangKuan = 1; // 横向缩放比例如 1.01 0.9
private static int intSuoFangGao = 1; // 纵向缩放比例如 1.01 0.9
private static int intFaZhi = 16; // 显示阀值
private static String strShuRu = "胡"; // 待取字模
private static String strZiTi = "文泉驿正黑"; // 待取字体
public JavaZiMo() {
}
public static void main(String[] args) {
BufferedImage image = new BufferedImage(intKuan, intGao, BufferedImage.TYPE_INT_BGR);
Graphics2D g = image.createGraphics();
Font myFont = new Font(strZiTi, Font.BOLD, 64); // 定义字体样式
g.setFont(myFont); // 设置字体
g.fillRect(0, 0, intKuan, intGao); // 绘制背景
g.setColor(new Color(0, 0, 0)); // 设置字体颜色
g.scale(intSuoFangKuan, intSuoFangGao); // 设置缩放
g.drawString(strShuRu, 0, 54);
g.dispose();
// 生成图片文件
// File f1 = new File("/tmp/11.jpg");
// try {
// ImageIO.write(image, "JPG", f1);
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
BufferedImage bi[] = new BufferedImage[16 * 16];
int intDianZhen[] = new int[16 * 16];
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
bi[i * 16 + j] = image.getSubimage(i * 4, j * 4, 4, 4);
}
}
for (int i = 0; i < bi.length; i++) {
int intD = 0;
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
intD += bi[i].getRGB(j, k) * -1;
}
}
if (intD > intFaZhi) {
intDianZhen[i] = 1;
}
}
for (int i = 0; i < 16; i++) {
StringBuffer sb = new StringBuffer();
for (int j = 0; j < 16; j++) {
if (intDianZhen[i + j * 16] == 1) {
sb.append("■");
} else {
sb.append("-");
}
}
System.out.println(sb.toString());
}
}
}
----■■----------
----■■---■■■■■■■
----■■---■■■■■■■
■■■■■■■■■■■--■■■
■---■■--■■■--■■■
----■■---■■■■■■■
----■■---■■--■■■
--■■■■■■-■■--■■■
--■■--■■-■■■■■■■
--■■--■■-■■■■■■■
--■■--■■-■■--■■■
--■■■■■■■■■--■■■
--■■--■■■■■--■■■
--■■--■■■■---■■■
-----■■■■--■■■■■
------■■----■■--
只能显示一个字,能不能 一次显示多个啊???