简体   繁体   English

使用Apache Batik调整SVG文件大小时内存不足

[英]OutofMemory while resizing svg file Using Apache Batik

i have generated svg file, using following code, 我已经使用以下代码生成了svg文件,

public class TestSVGGen {

        static BufferedImage img;

        public void paint(SVGGraphics2D g2d) {
                g2d.setPaint(Color.red);
                g2d.fill(new Rectangle(10, 10, 100, 100));
                g2d.drawImage(img, 0, 0, img.getWidth() ,img.getHeight(), null);
                g2d.setSVGCanvasSize(new Dimension(img.getWidth(), img.getHeight()));
        }

        public static void main(String[] args) throws IOException {

                img = ImageIO.read(TestSVGGen.class.getClassLoader().getResourceAsStream("images/test_offscreen.jpg"));

                // Get a DOMImplementation.
                DOMImplementation domImpl = GenericDOMImplementation
                                .getDOMImplementation();

                // Create an instance of org.w3c.dom.Document.
                String svgNS = "http://www.w3.org/2000/svg";
                Document document = domImpl.createDocument(svgNS, "svg", null);

                // Create an instance of the SVG Generator.
                SVGGraphics2D svgGenerator = new SVGGraphics2D(document);


                // Ask the test to render into the SVG Graphics2D implementation.
                TestSVGGen test = new TestSVGGen();
                test.paint(svgGenerator);

                // Finally, stream out SVG to the standard output using
                // UTF-8 encoding.
                boolean useCSS = true; // we want to use CSS style attributes
                File file = new File("image.svg");
                FileOutputStream fos = new FileOutputStream(file);
                Writer out = new OutputStreamWriter(fos, "UTF-8");
                svgGenerator.stream(out, useCSS);


        }

now , i want to re size this image canvas to 18,000 * 18000 in dimensions because i want to re size included image to this size , but whenever i try the following code (only portion of the code) 现在,我想将此图像画布的大小调整为18,000 * 18000,因为我想将包含的图像调整为该大小,但是每当我尝试以下代码时(仅代码的一部分)

svgCanvas.setSize(new Dimension(18000, 18000));

the program throws out of memory exception, 程序抛出内存不足异常

what should i do to re size to specified large size , is there any work around like tiling or segmentation of image . 我应该怎么做才能将尺寸调整为指定的大尺寸,是否有任何工作,例如平铺或分割图像。

i am very new to batik so please help me 我对蜡染很陌生,所以请帮助我

i solved my problem using TiledImageTranscoderfrom from contrib directory of batik and get a successful result without any out of memory error . 从蜡染的contrib目录中使用TiledImageTranscoder解决了我的问题并获得了成功的结果,而没有任何内存不足错误。

the above class uses just 35 MB of memory at a time when running from ECLIPSE IDE and takes 30 Sec on my machine to completely write the image file to disk. 从ECLIPSE IDE运行时,上述类一次仅使用35 MB内存,并且在我的计算机上花费30秒的时间将映像文件完全写入磁盘。

the result is in the TIFF though. 结果在TIFF中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM