my dog learned polymorphism
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Create and Save Image.." Watch "Create and Save Image.." New topic

Create and Save Image..

Tushar Bolinjkar

Joined: Apr 13, 2005
Posts: 2

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?

Joe Ess

Joined: Oct 29, 2001
Posts: 9189

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.


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.

So your string is getting written, it's just getting written off the visible image.
[ January 09, 2007: Message edited by: Joe Ess ]

[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.
I agree. Here's the link:
subject: Create and Save Image..
It's not a secret anymore!