Access to Color Picker

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Access to Color Picker

bartex9
Hi,
I'm the beginner in developing plugins. I would like to get access from my plugin to actual colors set in color picker in main ImageJ window. How can I do that?

Thanks in advance!
 
Reply | Threaded
Open this post in threaded view
|

Re: Access to Color Picker

Rasband, Wayne (NIH/NIMH) [E]
On Jan 10, 2015, at 7:36 AM, Bartłomiej Trzewiczek <[hidden email]> wrote:
>
> Hi,
> I'm the beginner in developing plugins. I would like to get access from my plugin to actual colors which are set in color picker in main ImageJ window. How can I do that?

Here is some JavaScript code that sets and accesses the color picker colors and draws them on an image:

  Toolbar.setForegroundColor(Color.red);
  Toolbar.setBackgroundColor(Color.blue);
  img = IJ.createImage("Colors", "RGB black", 512, 512, 1);
  ip = img.getProcessor();
  bg = Toolbar.getBackgroundColor();
  ip.setColor(bg);
  ip.setRoi(70,70,275,275);
  ip.fill();
  fg = Toolbar.getForegroundColor();
  ip.setColor(fg);
  ip.setRoi(170,170,275,275);
  ip.fill();
  img.updateAndDraw();
  img.show();

And here is the same code converted into a plugin:

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;

public class Colors_ implements PlugIn {

   public void run(String arg) {
      Toolbar.setForegroundColor(Color.red);
      Toolbar.setBackgroundColor(Color.blue);
      ImagePlus img = IJ.createImage("Colors", "RGB black", 512, 512, 1);
      ImageProcessor ip = img.getProcessor();
      Color bg = Toolbar.getBackgroundColor();
      ip.setColor(bg);
      ip.setRoi(70,70,275,275);
      ip.fill();
      Color fg = Toolbar.getForegroundColor();
      ip.setColor(fg);
      ip.setRoi(170,170,275,275);
      ip.fill();
      img.updateAndDraw();
      img.show();
   }

}



--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html