Dear Batik-experts,
could someone please tell me, how I can scale an image before I show it
on the canvas...
I've had a small runnable program below, and I just can't scale the
ellipse manually before it's shown on the screen.
best,
Cui
-----------------------------------------------------------------------------------------------
package resizeText;
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.util.SVGConstants;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class Resizer extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
private JSVGCanvas canvas;
private Document svgDoc;
private static final int ellipseX = 1500;
private static final int ellipseY = 1000;
private static final int canvasFixedWidth = 900;
private static final int canvasFixedHeight = 600;
public Resizer(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.canvas = new JSVGCanvas();
this.canvas.setDocumentState (JSVGCanvas.ALWAYS_DYNAMIC);
DOMImplementation dom =
SVGDOMImplementation.getDOMImplementation ();
svgDoc =
dom.createDocument(SVGConstants.SVG_NAMESPACE_URI,
SVGConstants.SVG_SVG_TAG, null);
this.initBall();
this.canvas.setDocument(svgDoc);
this.getContentPane().add(this.canvas, "Center");
/**
* here I tried to scale it by setting a new renderingtransform...
*/
AffineTransform at = canvas.getRenderingTransform();
at.scale(5, 5);
canvas.setRenderingTransform(at);
this.canvas.setMySize(new Dimension(canvasFixedWidth,
canvasFixedHeight));
this.pack();
this.setVisible(true);
}
private void initBall(){
Element rootE = svgDoc.getDocumentElement();
rootE.setAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE,
ellipseX*2+"");
rootE.setAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE,
ellipseY*2+"");
rootE.setAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE,
"0 0 "+ellipseX*4+" "+ellipseY*4);
Element ballE =
svgDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
SVGConstants.SVG_ELLIPSE_TAG);
rootE.appendChild(ballE);
ballE.setAttributeNS(null, SVGConstants.SVG_CX_ATTRIBUTE,
""+ellipseX);
ballE.setAttributeNS(null, SVGConstants.SVG_CY_ATTRIBUTE,
""+ellipseY);
ballE.setAttributeNS(null, SVGConstants.SVG_RX_ATTRIBUTE,
""+ellipseX);
ballE.setAttributeNS(null, SVGConstants.SVG_RY_ATTRIBUTE,
""+ellipseY);
}
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Resizer();
}
});
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]