Login  Register

Re: Filled Background when drawing a string

Posted by dscho on Jun 13, 2011; 1:58pm
URL: http://imagej.273.s1.nabble.com/Filled-Background-when-drawing-a-string-tp3684237p3684238.html

Hi Johannes,

On Mon, 13 Jun 2011, Johannes Weissmann wrote:

> I was wondering if there is a possiblility to set a background color
> when drawing a string using the functions of an image processor.
> Currently I am using a line like
>
> ip.drawString(string);
>
> I have to update the text several times and tried to avoid creating a
> TextRoi all the time. Does anyone know a quick solution or do I have to
> use TextROIs?

If you are already using Javascript or Java (as suggested by the snippet),
you could draw the string with (x +- 1, y +-1) and in the background color
to simulate an outline prior to drawing the string in the foreground
color.

If that is not what you meant, you can get the bounding box of a text ROI,
possibly extend it, and fill it before drawing the string.

In both cases, I would recommend making this functionality a method. Then
it is not _that_ bad if you have to do it a couple of times.

Ciao,
Johannes