Hi!
I am currently rendering a quite large image (to an offscreen PGraphics) and once i hit 10000px * 7000px I get the following error:
Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
at java.awt.image.Raster.createPackedRaster(Raster.java:467)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:331)
at processing.core.PImage.saveImageIO(PImage.java:3117)
at processing.core.PImage.save(PImage.java:3297)
at OffScreenRender.stopRender(OffScreenRender.java:38)
at MainVecField.draw(MainVecField.java:93)
at processing.core.PApplet.handleDraw(PApplet.java:2305)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2176)
at java.lang.Thread.run(Thread.java:724)
If I have the image at 9000px * 7000px everything is fine.
I am using IntelliJ idea as my IDE and I have increased the standard heap space from 512 to 2048mb. The image with the resolution
9000px * 7000px renders fine with 512mb heapspace, but the one with
10000px * 7000px does not (even with 2048 mb heap space).
This is my offScreenRender class:
- import processing.core.*;
- /**
- * Renders the ProcessingSketch to a ".jpg" file at specified resolution.
- */
- public class OffScreenRender
- {
- PApplet parent; // The parent PApplet
- PGraphics render;
- PGraphics original;
- int width;
- int height;
- int resFactor;
- OffScreenRender(PApplet p, int width_, int height_, int resFactor_)
- {
- //Initialize variables
- parent = p;
- width = width_;
- height = height_;
- resFactor = resFactor_;
- render = parent.createGraphics(width, height);
- }
- //Render the image
- void startRender()
- {
- parent.beginRecord(render);
- render.scale(resFactor);
- }
- //Render the image
- void stopRender()
- {
- parent.endRecord();
- render.save("hej.jpg");
- }
- }
This is my draw() function:
- public void draw()
- {
- frameRate(30);
- stroke(255);
- //Check if the render should be saved
- if(offScreenRenderSwitch == true){screenRender.startRender();}
- background(0,0,0);
- //Run vector field with action input
- vecField.run(action.get());
- action.display(g); //Display the action input
- //Load vector forces into drawGraphic
- graphic.loadVectorGuide(vecField.getForceVectors());
- //Render the background object
- backgroundVisual.display();
- //Draw the graphic from vectorForces
- graphic.display();
- if(offScreenRenderSwitch == true)
- {
- screenRender.stopRender();
- offScreenRenderSwitch = false;
- }
- }
So is this a Java error or do you think it could be a problem with the structure of my program?
Thank you!
1