• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to create a new image file?  RSS feed

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 9559
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!