Re: Programatic(Java) zooming issue(s)

Posted by Wayne Rasband-2 on
URL: http://imagej.273.s1.nabble.com/Programatic-Java-zooming-issue-s-tp5024578p5024598.html

> On Mar 31, 2021, at 10:09 PM, Fred Damen <[hidden email]> wrote:
>
> Greetings,
>
> Resizing image windows thru the GUI seems to always work as expected.
> Resizing the windows from within a Java plugin seem to work undesirably
> about 40% of the time.

Zooming image windows programmatically should work more reliably with the latest daily build (1.53j7). Most methods in the Zoom class now wait until the image window is activated.

Here is some JavaScript code that works as expected with the daily build and fails with earlier versions.

  IJ.run("Close All", "");
  img = IJ.openImage("https://imagej.net/images/blobs.gif");
  for (i=0; i<6; i++) {
     img2 = img.duplicate();
     img2.show();
     Zoom.set(img2, 2.5);
  }

-wayne


>  The undesirable effects tend to be consistent,
> e.g., the second,third, and fifth windows exhibit the same effect each
> time the plugin is run.  I suspect that the issue is some sort of a race
> condition between ImageJ and Java/System GUI proper, as the symptoms vary
> somewhat with load and computer.
>
> The symptoms include:
> Window has slightly wrong size and image appears to be the correct
> magnification.
> Window has correct size and the image is original size.
>
> Both these statements produce these results:
> IJ.run("In [+]", "");
> IJ.run("Set... ", "zoom=200");
>
> I have found that after show(ing) all the windows if I ...
>      Dimension ws = imps[0].getWindow().getSize();
>      for(ImagePlus imp : imps)
>         imp.getWindow().setSize(ws.width,ws.height);
>      for(ImagePlus imp : imps)
>         imp.getWindow().getCanvas().fitToWindow();
> This seems to adjust the window and image sizes appropriately most of the
> time.
>
> Is there a recommended way to zoom a window programmatically that works
> consistently and correctly like it does from Image>Zoom>... ?
>
> Thanks in advance,
>
> Fred

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html