• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Create and Save Image..

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need to create and save an image from my java code. Here is some code i have:-




This code creates and saves an image but its just black, whereas its supposed to have a red background and have abc written on it (see createImage method).

Any idea where i am going wrong?

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
You should become familiar with the Java API Documentation as it contains your answers. Why isn't the background red? The Java Doc for Graphics2D.setBackground says:


Setting the background color in the Graphics2D context only affects the subsequent clearRect calls and not the background color of the Component.


java.awt.Graphics2D

Why isn't the text showing up? The Java Doc for Graphics.drawString says:


The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system.


java.awt.Graphics
So your string is getting written, it's just getting written off the visible image.
[ January 09, 2007: Message edited by: Joe Ess ]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should also consider specifying the color of the text, it could be it's writing black on black.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic