Re: Transparent Fill in Circle

Posted by dscho on
URL: http://imagej.273.s1.nabble.com/Transparent-Fill-in-Circle-tp3698726p3698727.html

Hi,

On Wed, 1 Aug 2007, Ganesh Jothikumar wrote:

>           I have an image and I have drawn a circle on the image using Oval Roi and filled it with a random colour. Code snippet is below
>    
>   >                     ImagePlus imp = WindowManager.getCurrentImage();
> >                     ip = imp.getProcessor();
> >                     Roi roi = new OvalRoi(10,10,100,100);
> >                     ip.setColor(new Color(13,14,23));
> >                     ip.setMask(roi.getMask());
> >                     ip.setRoi(roi.getBoundingRect());
> >                     ip.fill(ip.getMask());
> >                     imp.updateAndDraw();
>
>   Now when the circle is filled it is opaque and it hides the portion of the image over which it is dawn. Nw I want it to be tranparent so that the circl is also filles with colour and at the same time the image bhind is also seen transparently.. Is there a way to do this... Any help is most welcome

I think that you have to use the "getImage()" method of ColorProcessor to
get a java.awt.Image, use "getGraphics()" on the result to get a
java.awt.Graphics instance.  On this instance, you can use "setColor()"
with a transparent colour, "fillRectangle()" to fill it, and then use the
original ImageProcessor's "setPixels()" method with the pixels obtained by
"new ColorProcessor(image).getPixels()" on the java.awt.Image.

Maybe you have to call ColorProcessor's
"setSnapshotPixels(ip.getPixels())" method before, and
"reset(ip.getMask())" after.  I don't know off-hand.

ImageJ does not know about transparency.

Hth,
Dscho