Re: Problem closing images
Posted by
Nathaniel Ryckman on
Jun 27, 2011; 3:38pm
URL: http://imagej.273.s1.nabble.com/Problem-closing-images-tp3683887p3683888.html
It would help if you were able to give the whole stack trace. My guess is that this line is giving you the problem:
Image result = WindowManager.getCurrentImage().getImage();From my experience, the getCurrentImage() command doesn't work very consistently. Maybe you could keep references of the images that you are opening up or encapsulate the getCurrentImage() command in a while loop that checks to see if the return value is valid.
strahli wrote
Hei everybody.
I'm working with ImageJ and Java for a month now. My task is it to read an Image every 10 seconds from a camera, compare it to a reference image and create a result Image (shows the differences). Means that I need to have 3 images open at once. I can repeat this process about 260 times until the <Out of memory> exception comes. My problem is that I tried to close the Images, but if I do this, I get another NullPointerException.
================================
My code is like this:
start timer
if (timerEvent) {
loadNewPicture();
}
loadNewPicture{
result = manipulate(refImage, snapshot);
...
}
manipulate (refImage, snapshot) {
if (refWindow == null) {
refWindow = new ImageWindow(refImage)
} else {
refWindow.setImage(refImage)
}
// the same for the snapshot
// execution of some macros
Image result = WindowManager.getCurrentImage().getImage();
return result;
}
================================
My problem is that I tried to close the images or the windows but if I do this , I get an exception in the class "ImageWindow" at row 526 (method "windowActivated" line: setMenuBar(Menus.getMenuBar());).
Btw: the image size is ca.70 KB.
Has anybody a hint for me?
Thanks in advance,
strahli
EDIT: And I've searched the older topics, but I didn't really found a solution except for closing the images, windows and using the garbage collector, but I can't really adapt it to my programm without getting other problems.