java读取屏幕文字_怎么用JAVA在显示屏(LED)上显示中文信息???要能一次显示多个字...

这篇博客展示了如何使用Java在显示屏上生成并显示中文字符,通过创建BufferedImage对象,设置字体样式,进行缩放和绘制裁剪后的图像。然而,当前的代码仅能显示一个字符,作者提出了疑问——如何实现一次显示多个汉字。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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());

}

}

}

----■■----------

----■■---■■■■■■■

----■■---■■■■■■■

■■■■■■■■■■■--■■■

■---■■--■■■--■■■

----■■---■■■■■■■

----■■---■■--■■■

--■■■■■■-■■--■■■

--■■--■■-■■■■■■■

--■■--■■-■■■■■■■

--■■--■■-■■--■■■

--■■■■■■■■■--■■■

--■■--■■■■■--■■■

--■■--■■■■---■■■

-----■■■■--■■■■■

------■■----■■--

只能显示一个字,能不能 一次显示多个啊???

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值