http://imagej.273.s1.nabble.com/ImagePlus-not-drawing-updates-with-in-a-loop-tp5007405p5007417.html
ImagePlus.setProcessor(ImageProcessor ip) updates the ImagePlus only if you have a new ImageProcessor (i.e., if it is a different object, irrespective of whether its contents have changed).
In your case, you use always the same ImageProcessor, so the operation is unnecessary except for the first time, and ImageJ recognizes that there is no new ImageProcessor.
To update the displayed ImagePlus, use the ImagePlus.updateAndDraw() method.
> Hello,
>
> I am making a plugin that uses imagePlus.insert() to add images to the canvas. These inserts are done within a loop. I want the imagePlus to be re-drawn for each iteration of the loop so that users can see each of the images as they are added. This works for the first time I run the loop but if I run it a second time it will not update the canvas within the loop. I have tried lots of different methods to let the imagePlus, imageProcesser and canvas know that there has been a change but nothing works. Here is some code:
>
> CustomCanvas cc = new CustomCanvas(imp3);
> CustomWindow cw = new CustomWindow(imp3, cc, 1);
> ...
> ImagePlus impLoop;
> for (int i=numOldImages;i<numImages;i++){ // Insert each image in it's correct location in the gallery
> impLoop = IJ.openImage(galleryImages.get(i));
> ipLoop = impLoop.getProcessor();
> float thumbHeight = idealHeight/thumbFactor;
> float thumbWidth = idealWidth/thumbFactor;
> if (currentCol > numColumns){ // Make new row if there are more than numColumns open images
> row = row + (int) thumbHeight;
> column = 0;
> currentCol = 1;
> }
> currentCol++;
> galleryOrder.add(galleryImages.get(i));
> ipLoop = ipLoop.resize((int) thumbWidth);
> ip3.insert(ipLoop, column, row);
>
> imp3.setProcessor(ip3); // This updates the gallery as each image is loaded for the 1st directory
>
> if (i == imageTally+numOldImages-1) {
> row = row + (int) thumbHeight;
> for (int k=0;k<maxNumCols - currentCol + 1;k++) { // Add spacers for empty slots in gallery
> galleryOrder.add(" ");
> }
> }
>
> System.gc();
> column = column + (int) thumbWidth;
>
> IJ.showStatus("Loading image: " + (i+1) +"/" + numImages + ", " + galleryImages.get(i));
> IJ.showProgress(i,numImages);
> }
>
> IJ.showStatus("Finished loading images!");
> imp3.show();
> imp3.draw();
> cc.setDrawingSize(screen.width-panelWidth, row+gutter); // redraws image
> cw.minimize(); // makes canvas match window size (with room for side panel)
> cw.setSize(ccSize);
> cc.setMagnification(1);
>
> The two calls imp3.setProcessor(ip3) and cc.setDrawingSize(screen.width-panelWidth, row+gutter) both cause the image to be updated, but neither can make it update in the loop.
>
> Also a similar thing happens with the progress bar. It shows up once, then in subsequent running of the loop it is not visible. Is there a way I can setVisble on the progress bar?
>
> thanks!
>
> Richard
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html