File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes text in canvas Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "text in canvas" Watch "text in canvas" New topic

text in canvas

meera sood
Ranch Hand

Joined: Dec 18, 2001
Posts: 50
I am trying to make a paintbrush kind of application in JAVA - wherein i have taken 2 canvases - one on a 1:1 scale and the other on a 6:1 scale. To draw on the canvases, i am using a 2-dimensional array of ints. I make changes to this array for drawing different shapes. I mean my paint() method for the 1:1 canvas has something like this in it:
public void paint(Graphics g)
for(int i=0;i<72;i++)
for(int j=0;j<14;j++)
g.setColor(new Color(0,246,0));
where pic_ref[][] is the array where is store the references for the canvases.
Now i want to add a utility for adding text to the canvases and this is where I am stuck. Further, I finally want to save this whole picture, including any text that I add, on the 1:1 canvas as a Jpeg file. I have no idea how to achieve this also. Can anybody please help me out with this???
Colin Kenworthy
Ranch Hand

Joined: Aug 06, 2001
Posts: 88
An idea might be to do this in reverse by putting the text onto the Graphics and copying the Graphics into your canvas.
Use drawString() or drawChars() on the Graphics object.
The BufferedImage class gives you a getRGB(int x, int y) method.
The problem is how to get a BufferedImage object from your Graphics object. I can't solve that one - anyone else suggest a way ?
The other option is to code all possible characters into your paint method.
Save as JPEG:
Can't be done in J2SE 1.3. It needs helper classes.
I agree. Here's the link:
subject: text in canvas
It's not a secret anymore!