File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create and Save Image..

 
Tushar Bolinjkar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • 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'
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Daniel Bauer
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should also consider specifying the color of the text, it could be it's writing black on black.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic