File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to create a new image file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to create a new image file?" Watch "How to create a new image file?" New topic
Author

How to create a new image file?

Luciano Queiroz
Ranch Hand

Joined: Feb 04, 2002
Posts: 172
Hi all!
Do you know how can I create a new image file (.jpeg) using Swing or Java 2D API?
I would like to draw a colorful rectangle and inside this rectangle write a sequence of 4 characters (the kind of font does not matter). But nothing will be rendered in a JFrame or JDialog nor an Applet.
What I want is create a new physical file (.jpeg or .bmp) containing this image.
I'll appreciate any good idea.
Thanks!


<b>Luciano Queiroz</b><br/>
 Brazil<br/>
 <i>SCJP 1.2, SCWCD, IBM 141, IBM 483, SCJP 1.4, IBM 484, IBM 287, SCBCD, SCEA, SCJP 5.0, SCJP 6.0, SCWCD 5</i>
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8924
    
    9

Drawing images without a GUI is not easy. From what I understand, you have to start the GUI with this flag: -Djava.awt.headless=true That lets the VM know you don't have a GUI. Next, create your BufferedImage instance and call getGraphics() on it to get the Graphics context. The Graphics object is what you use to draw with. That done, you can use javax.imageio.ImageIO or com.sun.image.codec.jpeg.JPEGImageEncoder to write the image to file (I've only used the latter). If you need more help, the
Java Tutorial is there for you.
Good Luck!


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a new image file?