Login  Register

Re: setIconImage

Posted by Sami Badawi-2 on Apr 20, 2008; 8:19pm
URL: http://imagej.273.s1.nabble.com/Save-TIFF-as-displayed-tp3696522p3696526.html

Hi Joachim,

java.awt.Image is an abstract super class for several concrete Image
implementation classes.
This method will turn any subclass of java.awt.Image into a BufferedImage:

        public static BufferedImage toBufferedImage(Image image, int newModelId) {
                BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
                                image.getHeight(null), newModelId);
                Graphics2D graphics = bufferedImage.createGraphics();
                graphics.drawImage(image, 0, 0, null);
                return bufferedImage;
        }

I am not sure if icons need to be a particular color model or size,
but this will change you image into an int RGB BufferedImage:

       ImageWindow win = imp.getWindow();
       BufferedImage bufferedIconInRGB =
toBufferedImage(imp.getImage(), BufferedImage.TYPE_INT_RGB);
       win.setIconImage(bufferedIconInRGB);

-Sami Badawi
http://www.shapelogic.org