sunmaster
asked on
putting text and image to tiff file
Hi,
Is there a java class to generate tiff file dynamically?Say i got a set of text and put it on a background image and i want to combine it to tiff file format. Can give me the any link to any website for reference?
thanks in advance.
sunmaster
Is there a java class to generate tiff file dynamically?Say i got a set of text and put it on a background image and i want to combine it to tiff file format. Can give me the any link to any website for reference?
thanks in advance.
sunmaster
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks,
but is there a simple example?
sunmaster
but is there a simple example?
sunmaster
Based on the example from javalamanc: http://www.javaalmanac.com/egs/javax.imageio/Graphic2File.html
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
public class Main
{
public static void main(String st[]) throws Exception
{
RenderedImage rendImage = myCreateImage();
// Write generated image to a file
try {
// Save as Tiff
File file = new File("newimage.tiff");
ImageIO.write(rendImage, "tiff", file);
} catch (IOException e) {
}
}
// Returns a generated image.
public static RenderedImage myCreateImage() {
int width = 100;
int height = 100;
// Create a buffered image in which to draw
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB );
// Create a graphics contents on the buffered image
Graphics2D g2d = bufferedImage.createGraphi cs();
// Draw graphics
g2d.setColor(Color.white);
g2d.fillRect(0, 0, width, height);
g2d.setColor(Color.black);
g2d.fillOval(0, 0, width, height);
// Graphics context no longer needed so dispose it
g2d.dispose();
return bufferedImage;
}
}
To run it you will need to add to your classpath the jars from: http://java.sun.com/products/java-media/jai/downloads/download-iio.html
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
public class Main
{
public static void main(String st[]) throws Exception
{
RenderedImage rendImage = myCreateImage();
// Write generated image to a file
try {
// Save as Tiff
File file = new File("newimage.tiff");
ImageIO.write(rendImage, "tiff", file);
} catch (IOException e) {
}
}
// Returns a generated image.
public static RenderedImage myCreateImage() {
int width = 100;
int height = 100;
// Create a buffered image in which to draw
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB
// Create a graphics contents on the buffered image
Graphics2D g2d = bufferedImage.createGraphi
// Draw graphics
g2d.setColor(Color.white);
g2d.fillRect(0, 0, width, height);
g2d.setColor(Color.black);
g2d.fillOval(0, 0, width, height);
// Graphics context no longer needed so dispose it
g2d.dispose();
return bufferedImage;
}
}
To run it you will need to add to your classpath the jars from: http://java.sun.com/products/java-media/jai/downloads/download-iio.html
http://www.geocities.com/marcoschmidt.geo/java-image-coding.html