我必须写一个字符串到.我正在使用 . 正在工作。上标,下标等不起作用。BufferedImageAtrributedStringTextAttribute.STRIKETHROUGH
public class TextAttributesSuperscript {
static String Background = "input.png";
static int curX = 10;
static int curY = 50;
public static void main(String[] args) throws Exception {
AttributedString attributedString= new AttributedString("this is data. this data should be super script");
attributedString.addAttribute(TextAttribute.FONT, new Font("TimesRoman", Font.PLAIN, 18));
attributedString.addAttribute(TextAttribute.FOREGROUND, Color.BLACK);
attributedString.addAttribute(TextAttribute.FONT, new Font("TimesRoman", Font.BOLD, 18), 30,33);
attributedString.addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 29,33);
attributedString.addAttribute(TextAttribute.SUPERSCRIPT,TextAttribute.SUPERSCRIPT_SUPER,30,33);
final BufferedImage image = ImageIO.read(new File(Background));
Graphics g = image.getGraphics();
g.drawString(attributedString.getIterator(), curX, curY);
g.dispose();
ImageIO.write(image, "png", new File("output.png"));
}
}
在执行上述代码时。上标部分不起作用(文本未像上标一样打印)
慕田峪7331174
相关分类