Login  Register

Re: Active Image or Threading Problem

Posted by BenTupper on Oct 31, 2009; 2:29pm
URL: http://imagej.273.s1.nabble.com/Active-Image-or-Threading-Problem-tp3690601p3690603.html

Hi David,

On Oct 31, 2009, at 2:24 AM, David William Webster wrote:

> All,
>
> I am getting some funny results with the code fragment below. The
> IJ.makeOval(...) method works on the current active image. In case  
> 1, when
> I leave IJ.log("2: The ... ) commented out, the oval shows up on  
> drawn on
> image ip1. I would have thought it would shown up on ip2. In case 2,  
> I un-
> comment IJ.log("2: The ... ), then the oval it does show up super-
> imposed
> on ip2. Sometimes, things work the other way around, at least in the  
> first
> case. Am I getting some sort of multi-threading problem or does the  
> method
> call in the IJ.log(...) somehow change the active image? In any  
> case, how
> can I insure that ip2 is the active image.
>

The following always draws the oval on "ip2" for me.  You might be  
right about the thready thing; using  
WindowManager.setTempCurrentImage() seems to work for this thread.

        ImageProcessor ip1 = new ByteProcessor(100,100);
        ImageProcessor ip2 = new ByteProcessor(100,100);
                               
        ImagePlus imp1 = new ImagePlus("ip1", ip1);
          imp1.show();
        ImagePlus imp2 = new ImagePlus("ip2", ip2);
        imp2.show();

        WindowManager.setTempCurrentImage(imp2);

        IJ.log("2: The current image is  
"+WindowManager.getCurrentImage().getTitle());
        IJ.makeOval(0,0, 70,70);


Cheers,
Ben


> David Webster
>
>
>
> ImageProcessor ip1 = new ByteProcessor(100,100);
> ImageProcessor ip2 = new ByteProcessor(100,100);
>
> new ImagePlus("ip1", ip1).show();
> new ImagePlus("ip2", ip2).show();
>
> //IJ.log("2: The current image is "+WindowManager.getCurrentImage
> ().getTitle());
>
> IJ.makeOval(0,0, 70,70);


Cheers,
Ben