引用来自“tcxu”的评论
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class DrawLattice extends JFrame {
int lattice[][]={ // 汉字 上
{0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,1,1,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0}
};
public DrawLattice() {
super("点阵转成图片");
setVisible(true);
setSize(300,200);
}
public void paint( Graphics g ) {
g.setColor(Color.yellow);
g.fillRect(0,0,400,400);/*画黄色背景*/
/* 根据 二维数组的数值,画出对应的黑白图片 */
for (int i=0; i
for (int j=0;j
if (lattice[i][j]==0)
g.setColor(Color.black);
else
g.setColor(Color.white);
g.fillRect(30+j*10, 50+i*10,10,10);
}
}
public static void main(String args[]){
new DrawLattice();
}
}
int width = 32;
int height = 32;
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphic = bi.createGraphics();
graphic.setColor(new Color(0,0,0));
graphic.fillRect(0, 0, width, height);
int k = 0;
for (int i = 0; i < width; i++) {
for (int j = height; j >0; j--) {
if (array[k] == 1 ) {
bi.setRGB(i, j, 0xFFFFFF);
}
k++;
}
}
多谢!
最后我用了另一种方法,新建一张黑色的位图,条件匹配的时候用白色像素块替换掉黑色像素块
我的源数据是byte转的整数一维数组2333