On Tue, Jun 12, 2012 at 2:28 PM, alexwatson <
[hidden email]> wrote:
> Yeah I was trying to find it in the API, however I never looked under the
> ImageProcessor class.
>
It can be kind of difficult. I still don't know my way around the API that
well. I've had some luck on the main developer page by putting a good
guess of search term into the search box for "browsable source". From a
section of code, you can possibly track the method back to it's class. A
couple other things to try are the macro recorder, (in javascript mode),
and, at least in Fiji, the Command Finder (ctrl-L, type a command, and
check "show full information") if there are menu equivalents.
> Anyways, I am using the code below now, but it isn't
> changing the font size, strangely:
>
> ImageProcessor resultProcessor = resultImg.getProcessor();
> Font biggerFont = new Font("Arial", Font.PLAIN, 100);
> resultProcessor.setFont(biggerFont);
>
Well, it's only a snippet, but I'll speculate. The drawString method
actually changes pixels in the image, so after resultProcessor.setFont(),
you have to do resultProcessor.drawString(). setFont() only changes the
font size of FUTURE strings. Finally, don't forget to do
resultImg.updateAndDraw() to refresh the display.
In a Jython script, the following works for me to change font size. (There
has to be an open image, and you'll obviously have to convert to pure Java
for a plugin.)
from java.awt import Font
image = IJ.getImage()
resultProcessor = image.getProcessor()
for fontSize in [10,20,30,40,50]:
biggerFont = Font("Arial", Font.PLAIN, fontSize)
resultProcessor.setFont(biggerFont)
resultProcessor.drawString("font size = "+ str(fontSize), 50,
fontSize*10)
image.updateAndDraw()
Hope this gets you going in the right direction.
*Jim Passmore*
Research Associate
Sealed Air Corporation
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html