There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:You are doing the scaling manually. You can let java do all the hard work. Have a look at the AffineTransform class and if g is a Graphics2D, g.setTransform(...). You can obtain a Graphics2D instance with: Graphics2D g2d = (Graphics2d) g.createGraphics())
Also: two possible strategies come to mind:
1) draw the BufferedImage first, and use it in the paintComponent method. In this paintComponent, draw the BI according to the current size of the panel.
2) do the complete drawing in a separate method, with parameter Graphics g. Then in the paintComponent, you call it with the supplied Graphics, and if you want to create a BufferedImage that fits the current size of the panel, you call the method with the Graphics from the BufferedImage (like: buf.createGraphics). If necessary, use a Graphics2D.
Robert Bray wrote:I really don't need image to go the display - just to the file. New code is below.
There are three kinds of actuaries: those who can count, and those who can't.
Paul Clapham wrote:
Robert Bray wrote:I really don't need image to go the display - just to the file. New code is below.
Then do like Norm said. Create the BufferedImage and get a Graphics object from it. Right now you're doing that but you ignore (and discard) the Graphics object. What you should do next is to use the code which is now in the paint() method and use that to update the Graphics object which is returned from BI.createGraphics(). Once you've done that you can write the BI to your disk file.
Also, since you don't need the image to go to the display, there's no need for your Plat class to be a JPanel. I don't think you need a GUI at all to create this image file.
I am out of memoryheap
There are three kinds of actuaries: those who can count, and those who can't.
Norm Radder wrote:Where are the recursive calls? Is there a path where methods call each other directly or indirectly?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |