Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Apache Batik调整svg文件大小时OutofMemory_Java_Svg_Java 2d_Batik - Fatal编程技术网

Java 使用Apache Batik调整svg文件大小时OutofMemory

Java 使用Apache Batik调整svg文件大小时OutofMemory,java,svg,java-2d,batik,Java,Svg,Java 2d,Batik,我已经使用以下代码生成了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.dra

我已经使用以下代码生成了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);


        }
现在,我想将这个图像画布的尺寸重新调整为18000*18000,因为我想将包含的图像的尺寸重新调整为这个尺寸,但是每当我尝试以下代码时(仅部分代码)

程序抛出内存不足异常

我应该怎么做来重新调整到指定的大尺寸,是否有任何工作,如图像的平铺或分割


我对batik非常陌生,所以请帮助我

我使用batik的contrib目录中的TileImage TranscoderFrom解决了我的问题,并获得了一个成功的结果,没有任何内存不足错误

当从EclipseIDE运行时,上面的类一次只使用35MB的内存,在我的机器上需要30秒才能将映像文件完全写入磁盘


结果是在TIFF中。

我使用来自batik的contrib目录的TileImage TranscoderFrom解决了我的问题,并且获得了成功的结果,没有任何内存不足错误

当从EclipseIDE运行时,上面的类一次只使用35MB的内存,在我的机器上需要30秒才能将映像文件完全写入磁盘


结果是TIFF。

我认为这种大小的调整大小操作会消耗JVM中的大量内存。增加JVM的内存,然后再试一次,我不知道它需要多少内存,也不知道框架本身是否有办法解决这个问题,尽管…@Thihara我的问题不是增加内存,应该有一种分割或平铺等方法。我认为这种大小的调整操作会消耗JVM中的大量内存。增加JVM的内存,然后再试一次,我不知道它需要多少内存,也不知道框架本身是否有办法解决这个问题,尽管……@Thihara我的问题不是增加内存,应该有一种分割或平铺的方法。
svgCanvas.setSize(new Dimension(18000, 18000));