Login  Register

Re: Fill an ROI with transparent color (alpha value)

Posted by dscho on May 21, 2011; 3:35pm
URL: http://imagej.273.s1.nabble.com/Fill-an-ROI-with-transparent-color-alpha-value-tp3684492p3684496.html

Hi Jan,

On Sat, 21 May 2011, Jan Eglinger wrote:

> I'd like to fill an ROI (e.g. rectangle or arrow) with a
> half-transparent color (i.e. alpha = 0.5).
>
> How can I do this with Javascript?
>
> I tried with
>   ip.setColor(new Color(r/255,g/255,b/255,alpha));
>   roi.drawPixels(ip);
> which works for TextRois, but when I try similar for other ROIs:
>   ip.setColor(new Color(r/255,g/255,b/255,alpha));
>   ip.fill(roi);
> seems to ignore the alpha value.

I fear that you have to get an AWT image via ImageProcessor's getImage()
method, get the corresponding Graphics object via getGraphics(),
then convert the ROI into an AWT Shape via new ShapeRoi(roi).getShape()
and then use the Graphics' methods to fill or draw the Shape.

Ciao,
Dscho