Using Graphics2D to overlay text on a BufferedImage and return a BufferedImage

Posted by Andrew Bolster on Stack Overflow See other posts from Stack Overflow or by Andrew Bolster
Published on 2010-04-17T13:48:12Z Indexed on 2010/04/17 13:53 UTC
Read the original article Hit count: 538

Filed under:
|
|

I have checked similarly named questions, but they don't answer this use case.

Basically, I was to overlay some text (text) at a given coordinate (x,y) I have the below function in a package;

protected BufferedImage Process2(BufferedImage image){
    Graphics2D gO = image.createGraphics();
    gO.setColor(Color.red);
    gO.setFont(new Font( "SansSerif", Font.BOLD, 12 ));
    gO.drawString(this.text, this.x, this.y);
    System.err.println(this.text+this.x+this.y);
    return image;
}

I feel like im missing something patently obvious; every reference to Graphics2D I can find is dealing with either games or writing directly to a file but I just want a BufferedImage returned. with the overlay 'rendered'

In the current code, the image appears out the end unchanged.

Thanks!

© Stack Overflow or respective owner

Related posts about java

Related posts about graphics2d