Re: Fill an ROI with transparent color (alpha value)
Posted by
Rasband, Wayne (NIH/NIMH) [E] on
May 21, 2011; 5:17pm
URL: http://imagej.273.s1.nabble.com/Fill-an-ROI-with-transparent-color-alpha-value-tp3684492p3684493.html
On May 21, 2011, at 11:25 AM, Jan Eglinger wrote:
> Dear all,
>
> 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.
You can do this by using the ImagePlus flatten() method. Here is an example:
imp = IJ.openImage("
http://imagej.nih.gov/ij/images/FluorescentCells.zip");
roi = new OvalRoi(130, 118, 254, 239);
r=150; g=0; b=150; alpha=0.5;
roi.setFillColor(new Color(r/255,g/255,b/255,alpha));
imp.setOverlay(new Overlay(roi));
imp = imp.flatten();
imp.show();
-wayne