本文介绍了JAVA扩展ASCII表使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我需要从图像上显示的扩展ASCII表获取字符。但是当我把十进制值转换为char时,我得到不同的字符。这些字符在JAVA中的真正价值是什么。
private void generateAsciiMatrix()
{
// 32 - 255是ascii表中的可见字符
for(int i = 32; i {
this.generateAsciiMatrix一世);
}
}
private void generateAsciiMatrix(char letter)
{
EBufferedImage character = new EBufferedImage(
ImageClass.charToImage宽度,高度));
//...some代码
}
public static BufferedImage charToImage(char c,int width,int height)
{
BufferedImage off_Image = new BufferedImage(width,height,
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2 = off_Image.createGraphics();
g2.setColor(Color.black);
g2.setBackground(Color.WHITE);
g2.clearRect(0,0,width,height);
g2.setFont(new Font(Monospaced,Font.PLAIN,12));
g2.drawString(Character.toString(c),0,height);
saveImage(off_Image,code+(int)c);
return off_Image;感谢您的帮助,对不起我的可怜的英语: - ) / p>
>
解决方案我的解决方案这个问题是我手动创建一个字符数组与我需要的字符
in my app I need to get character from extended ASCII table that is shown on the image. But when I cast decimal values into char, I get different characters. What is the real value of these characters in JAVA. I dont write the character on console or in a file, just into the image.
private void generateAsciiMatrix()
{
//32 - 255 are visible characters in ascii table
for(int i = 32; i < 256; i++)
{
this.generateAsciiMatrix((char)i);
}
}
private void generateAsciiMatrix(char letter)
{
EBufferedImage character = new EBufferedImage(
ImageClass.charToImage(letter, width, height));
//...some code
}
public static BufferedImage charToImage(char c, int width, int height)
{
BufferedImage off_Image = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2 = off_Image.createGraphics();
g2.setColor(Color.black);
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.setFont(new Font("Monospaced", Font.PLAIN, 12));
g2.drawString(Character.toString(c), 0, height);
saveImage(off_Image, "code" + (int)c);
return off_Image;
}
Thank you for your help, and sorry for my poor English :-)
解决方案 My solution for this problem is that I manualy created a char array with those characters I needed
这篇关于JAVA扩展ASCII表使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!