Heap problems - with image
in
Programming Questions
•
8 months ago
Hi
I am trying to do a pile of work in an off screen buffer that is considerably bigger than my screen.
I am also trying to display part of that buffer to the screen.
Following is a very stripped down version of the code.
it gets the following error:
An OutOfMemoryError means that your code is either using up too much memory
because of a bug (e.g. creating an array that's too large, or unintentionally
loading thousands of images), or that your sketch may need more memory to run.
If your sketch uses a lot of memory (for instance if it loads a lot of data files)
you can increase the memory available to your sketch using the Preferences window.
Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
at processing.core.PImage.init(PImage.java:243)
at processing.core.PImage.<init>(PImage.java:229)
at processing.core.PImage.get(PImage.java:813)
at imagetest.draw(imagetest.java:52)
at processing.core.PApplet.handleDraw(PApplet.java:2142)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
at processing.core.PApplet.run(PApplet.java:2020)
at java.lang.Thread.run(Thread.java:662)
Removing the line image(myImage,0,0); stops the error. (but of course defeats the purpose)
I have tried reading other posts involving heaps, but nothing....
I have tried increasing memory, just cause the crash to come a little later.
Please Help
This is most frustrating.
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PImage;
import processing.core.PGraphics;
import processing.core.PImage;
PImage picture;
PImage myImage;
PGraphics flowmap;
PGraphics gbuff;
void setup()
{
size(500,500);
picture = loadImage("BO.jpg");// an ~ 5000*3000 photo
this.width = picture.width;
this.height = picture.height;
gbuff = createGraphics(width, height);
gbuff.beginDraw();
gbuff.background(255); // set to white
gbuff.image(picture, 0, 0, width, height);
gbuff.endDraw();
}
void draw()
{
myImage = gbuff.get(mouseX,mouseY,500,500);
image(myImage,0,0);
}
1