aspose file tools*
The moose likes Java in General and the fly likes Create and Save Image.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Create and Save Image.." Watch "Create and Save Image.." New topic
Author

Create and Save Image..

Tushar Bolinjkar
Greenhorn

Joined: Apr 13, 2005
Posts: 2
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'
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Daniel Bauer
Ranch Hand

Joined: Apr 15, 2006
Posts: 49
You should also consider specifying the color of the text, it could be it's writing black on black.
 
 
subject: Create and Save Image..