Chinese font dot matrix

T

Thomas Fritsch

terry said:
Hi,
Hi!

Do anyone know how to get the font matrix of a Chinese character?

Thanks!
You can do like for any font:
Create a BufferedImage, draw a string into it with a font of your
choice, and get the pixels from the image.
The following code dumps out the pixels of the character 'A' rendered
with font "Dialog" (size 48).

BufferedImage image = new BufferedImage(50, 50,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, image.getWidth(), image.getHeight());
g.setColor(Color.black);
g.setFont(new Font("Dialog", Font.PLAIN, 48));
g.drawString("A", 0, image.getHeight());
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int pixel = image.getRGB(x, y);
// 0xff000000 = black, 0xffffffff = white
System.out.print(((pixel & 0xFFFFFF) != 0) ? '.' : '*');
}
System.out.println();
}


To get the pixels of a chinese character
* replace "A" by a chinese string (for example "\u4e2d")
* replace "Dialog" by a chinese font (for example "Batang")
in the code above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top