• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to create a new image file?

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic