JavaでPNG画像作成
private int x = 100;
private int y = 12;private void execute(String string) throws IOException {
BufferedImage im = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);
Graphics g = im.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, im.getWidth(), im.getHeight());
g.setColor(Color.black);
g.drawString(string, 0, 10);
im.flush();ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedOutputStream os = new BufferedOutputStream(bos);
ImageIO.write(im, "png", os);
//output
FileOutputStream fos=new FileOutputStream("R:/test.png");
fos.write(bos.toByteArray());
fos.close();
}
とりあえず引数の文字列を画像にするだけだけど、さくっとできた。