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

text in canvas

 
meera sood
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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++)
{
if(logo.pic_ref[i][j]==0)
g.setColor(Color.black);
else
g.setColor(new Color(0,246,0));
g.fillRect(i,j,1,1);
}
}
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???
P.S I DO NOT WANT TO USE ANY THIRD PARTY SOFTWARE.
 
Colin Kenworthy
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Text:
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. http://www.javaranch.com/ubb/Forum1/HTML/001462.html http://www.javaranch.com/ubb/Forum1/HTML/002440.html
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic