Re: Problems with Overlay.show

Posted by Stein Rørvik on
URL: http://imagej.273.s1.nabble.com/Problems-with-Overlay-show-tp5020948p5021011.html

Thank you for the fix, the example macro now works fine.

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
Sent: 27. juli 2018 05:10
To: [hidden email]
Subject: Re: Problems with Overlay.show

> On Jul 12, 2018, at 11:10 AM, Stein Rørvik <[hidden email]> wrote:
>
> Here is another overlay issue:
>
> It seems that text added with Overlay.drawString is lost when text is
> added using Overlay.addSelection, _unless_ Overlay.show is called before the first instance of Overlay.addSelection.

This bug is fixed in the latest ImageJ daily build (1.52f7).

-wayne

> If Overlay.show is called after Overlay.addSelection, the text added with Overlay.addSelection is lost instead.
> So combining Overlay.drawString and Overlay.addSelection only works if Overlay.show is called at the right place.
>
> Being able to combine Overlay.drawString and Overlay.addSelection is
> useful because the former is bottom adjusted and the latter is top adjusted.
>
> See this example macro.
> The three functions are identical except for the code line position of
> Overlay.show;
>
> close("boats*");
> run("Boats (356K)");
> TextStr1 = "This is test text 1";
> TextStr2 = "This is test text 2";
> TextStr3 = "This is test text 3";
> TextStr4 = "This is test text 4";
> xPos = getWidth/2;
> yPos = round(getHeight/7);
> setFont("SansSerif", 28, "antialiased"); setColor("red");
>
> OverlayTest1();
> OverlayTest2();
> OverlayTest3();
> run("Tile");
>
> function OverlayTest1() {
>                run("Boats (356K)");
>
>                //draw text using Overlay.drawString
>                Overlay.drawString(TextStr1, xPos, yPos*1);
>
>                //draw text using Overlay.addSelection
>                makeText(TextStr2, xPos, yPos*2);
>                Overlay.addSelection("yellow");
>
>                //repeat the above
>                Overlay.drawString(TextStr3, xPos, yPos*3);
>                makeText(TextStr4, xPos, yPos*4);
>                Overlay.addSelection("yellow");
>
>                Overlay.show;
>                run("Select None");
>                //problem: only TextStr1 is shown }
>
> function OverlayTest2() {
>                run("Boats (356K)");
>
>                //draw text using Overlay.drawString
>                Overlay.drawString(TextStr1, xPos, yPos*1);
>
>                //draw text using Overlay.addSelection
>                makeText(TextStr2, xPos, yPos*2);
>                Overlay.addSelection("yellow");
>
>                //draw text using Overlay.drawString
>                Overlay.drawString(TextStr1, xPos, yPos*3);
>
>                //repeat the above
>                Overlay.drawString(TextStr3, xPos, yPos*3);
>                makeText(TextStr4, xPos, yPos*4);
>                Overlay.addSelection("yellow");
>
>                run("Select None");
>                //problem: TextStr1 is not shown }
>
> function OverlayTest3() {
>                run("Boats (356K)");
>
>                //draw text using Overlay.drawString
>                Overlay.drawString(TextStr1, xPos, yPos*1);
>                Overlay.show;
>
>                //draw text using Overlay.addSelection
>                makeText(TextStr2, xPos, yPos*2);
>                Overlay.addSelection("yellow");
>
>                //draw text using Overlay.drawString
>                Overlay.drawString(TextStr1, xPos, yPos*3);
>
>                //repeat the above
>                Overlay.drawString(TextStr3, xPos, yPos*3);
>                makeText(TextStr4, xPos, yPos*4);
>                Overlay.addSelection("yellow");
>
>                run("Select None");
>                //now all strings are shown }
>
> I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.
>
> Stein

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

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