drawString function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

drawString function

pang
Dear all,

 

A quick question for drawString("txt",i,j) on an image. How is "txt"
placed in the image? Is the center of x (for example, x has a font size
of 32) is at the location (i,j).

 

I used some other software to calculate the center of the cells, but
when I put a star at the cell center, I noticed that it is located above
the cell center. Anyone has an insight about how drawstring works.

 

Thanks,

 

Zhengyu

 

 

Zhengyu Pang, Ph.D.

Biochemistry and Bioanalytics Laboratory

Diagnostic and Biomedical Technologies

GE Global Research, K1-5B37A

One Research Circle

Niskayuna, NY 12309

T: 518-387-4015

F: 518-387-7765

 
Reply | Threaded
Open this post in threaded view
|

Re: drawString function

Michael Schmid
Hi Zhengyu,

the coordinates x, y of drawString, (i,j in your example) are at the bottom left corner of the box enclosing the text.

To get an uppercase text centered at x, y, use
  setFont("SansSerif", 32);
  drawString(txt,x-getStringWidth(txt)/2, y+getValue("font.height")/2);

Note that the lowercase 'x' will have its center below; you will get it roughly centered when replacing "font.height" with "font.size".


Michael
________________________________________________________________
On May 22, 2012, at 16:16, Pang, Zhengyu (GE Global Research) wrote:

> Dear all,
>
> A quick question for drawString("txt",i,j) on an image. How is "txt"
> placed in the image? Is the center of x (for example, x has a font size
> of 32) is at the location (i,j).
>
> I used some other software to calculate the center of the cells, but
> when I put a star at the cell center, I noticed that it is located above
> the cell center. Anyone has an insight about how drawstring works.
>
> Thanks,
>
> Zhengyu
Reply | Threaded
Open this post in threaded view
|

Re: drawString function

pang
Michael,

Thanks for your help. It works. I found that following program could
give you the same results by utilizing the center justification.

  setFont("SansSerif", 32);
  setJustification("center");
  drawString(txt,x, y+getValue("font.height")/2);

Cheers,

Zhengyu

PS: for the macro functions, we should have a little bit more details
than it is currently written. The information such as
" the coordinates x, y of drawString, (i,j in your example) are at the
bottom left corner of the box enclosing the text" should be added.


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
Michael Schmid
Sent: Tuesday, May 22, 2012 12:26 PM
To: [hidden email]
Subject: Re: drawString function

Hi Zhengyu,

the coordinates x, y of drawString, (i,j in your example) are at the
bottom left corner of the box enclosing the text.

To get an uppercase text centered at x, y, use
  setFont("SansSerif", 32);
  drawString(txt,x-getStringWidth(txt)/2, y+getValue("font.height")/2);

Note that the lowercase 'x' will have its center below; you will get it
roughly centered when replacing "font.height" with "font.size".


Michael
________________________________________________________________
On May 22, 2012, at 16:16, Pang, Zhengyu (GE Global Research) wrote:

> Dear all,
>
> A quick question for drawString("txt",i,j) on an image. How is "txt"
> placed in the image? Is the center of x (for example, x has a font
> size of 32) is at the location (i,j).
>
> I used some other software to calculate the center of the cells, but
> when I put a star at the cell center, I noticed that it is located
> above the cell center. Anyone has an insight about how drawstring
works.
>
> Thanks,
>
> Zhengyu