Osi*_*ify 1 java fonts truetype
是否有任何 Java 库可用于从真字体 (.ttf) 中提取每个字符?
字体的每个字符,我想:
任何人都可以帮助向我展示上述目的的一些提示吗?
PS:我想弄清楚,这个应用程序是如何制作的:http : //www.softpedia.com/progScreenshots/CharMap-Screenshot-94863.html
这会将 a 转换String为 a BufferedImage:
public BufferedImage stringToBufferedImage(String s) {
//First, we have to calculate the string's width and height
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g = img.getGraphics();
//Set the font to be used when drawing the string
Font f = new Font("Tahoma", Font.PLAIN, 48);
g.setFont(f);
//Get the string visual bounds
FontRenderContext frc = g.getFontMetrics().getFontRenderContext();
Rectangle2D rect = f.getStringBounds(s, frc);
//Release resources
g.dispose();
//Then, we have to draw the string on the final image
//Create a new image where to print the character
img = new BufferedImage((int) Math.ceil(rect.getWidth()), (int) Math.ceil(rect.getHeight()), BufferedImage.TYPE_4BYTE_ABGR);
g = img.getGraphics();
g.setColor(Color.black); //Otherwise the text would be white
g.setFont(f);
//Calculate x and y for that string
FontMetrics fm = g.getFontMetrics();
int x = 0;
int y = fm.getAscent(); //getAscent() = baseline
g.drawString(s, x, y);
//Release resources
g.dispose();
//Return the image
return img;
}
Run Code Online (Sandbox Code Playgroud)
我认为没有办法获取所有字符,您必须创建一个String或char数组来存储要转换为图像的所有字符。
一旦你拥有了String或char[]你想要转换的所有键,你就可以轻松地迭代它并转换调用stringToBufferedImage方法,然后你就可以了
int charCode = (int) charactersMap.charAt(counter);
Run Code Online (Sandbox Code Playgroud)
如果charactersMap是String, 或
int charCode = (int) charactersMap[counter];
Run Code Online (Sandbox Code Playgroud)
如果charactersMap是一个char数组
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
4129 次 |
| 最近记录: |