Hi,
I need to insert/write text into an existing image and I would like to know if someone has some experience with this. The goal is to open an image then write some text on it and then save it. The saved image should be displayed with the text wrote before.
At this moment I can open the image:
FileSeekableStream stream = new FileSeekableStream(imageFilename);
TIFFDecodeParam decodeParam = new TIFFDecodeParam();
decodeParam.setDecodePaletteAsShorts(true);
ParameterBlock params = new ParameterBlock();
params.add(stream);
RenderedOp image1 = JAI.create("tiff", params);
BufferedImage img = image1.getAsBufferedImage();
With the BufferedImage object, I can display the image with a graphics object and display some text too.
public void paint(Graphics g) {
Dimension size = getSize();
g.drawImage(img,
0, 0, size.width, size.height,
0, 0, img.getWidth(null), img.getHeight(null),
null);
Font font = new Font("Serif", Font.PLAIN, 18);
g.setFont(font);
g.setColor(Color.black);
g.setFont(font);
g.drawString("Some Text...", 10,10);
}
The idea is to do something similar without displaying the image and without using a graphics object or, someone know if is possible to save the objects displayed from the graphics object into an image?
I have been looking for some class in JAI that let me do that, but I haven't found the way to do it.
Any ideas would be appreciated