This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 8263

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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to create a new image file?
 
Similar Threads
Image Coordinates and Scaling
Images
how do i capture screenshot via network in java swing
Saving runtime Swing UI as image
After screen Capture(to a Gif File)?????????