HI,
Dimension canvassize = view.getCanvas().getSize();
HI,
Dimension canvassize = view.getCanvas().getSize();
Take a look at the following topic in this forum (topic “Export Image from JGoView”:
Thanks for the reply. I am using the following code to save the JGoView as an image file
JGoView view = getJgoView();
<span =“Apple-tab-span” style=“white-space:pre”> Dimension canvassize = view.getDocumentSize();
<span =“Apple-tab-span” style=“white-space:pre”> final int _width = canvassize.width;
<span =“Apple-tab-span” style=“white-space:pre”> final int _height = canvassize.height;
<span =“Apple-tab-span” style=“white-space:pre”> view.setSize(_width, _height);
<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> view.getCanvas().setSize(_width, _height);
<span =“Apple-tab-span” style=“white-space:pre”> BufferedImage bi = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
<span =“Apple-tab-span” style=“white-space:pre”> Graphics2D g2 = (Graphics2D)bi.getGraphics();
<span =“Apple-tab-span” style=“white-space:pre”> g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
<span =“Apple-tab-span” style=“white-space:pre”> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> view.getCanvas().paint(bi.createGraphics());
<span =“Apple-tab-span” style=“white-space:pre”> ImageIO.write(bi, “png”, outputFile);
I have the following problems
But when i dont put JGoView in the JFrame, after building JGoView object, directly try to convert it into image, my image is not layout properly.
I tried to print out the JGoView object but in the print out also, we i use JFrame to put the JGoView and do frame.pack() and frame.setVisible(true), printout come properly otherwise when i dont use any frame, and just do print out using JGoView object, printout image is not layout properly (Shape and size are not coming properly).
So, I just wanted to know, to layout the JGoView component properly, do we need to put into some container? Or do we have any other direct call to layout if we are not putting JGoView obj into any container._
No, you shouldn’t need any special container. In fact, if you replace the first line above with:
JGoView view = new JGoView();
The JGoView is clearly not contained in any special container and it seems to work fine.