Link to home
Start Free TrialLog in
Avatar of hzinox
hzinox

asked on

Problem to display WritableRaster

Hi all,

Can anyone help me out with WritableRaster? How can I display a WritableRaster? I have accessed each pixel RGB values and compare each of them to a series of RGB values (which represents cluster centers). After accessing and comparing, the RGB value of pixels which satisfied a distance condition are changed into WHITE pixels. After all pixels in the original image had been evaluated and modified, I want to display the modified image.

I have problem with the last task. Any help is much appreciated.

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Create a BufferedImage. See

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/BufferedImage.html#BufferedImage(java.awt.image.ColorModel, java.awt.image.WritableRaster, boolean, java.util.Hashtable)
Avatar of hzinox
hzinox

ASKER

Hi CEHJ,

Actually I am using BufferedImage. Below is my code snippet

    inputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphic = inputImage.createGraphics();
    graphic.drawImage(image, 0, 0, this);
    outputImage =  new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    WritableRaster input = inputImage.copyData(null);
    WritableRaster output = outputImage.getRaster();
   //access each pixel using r=input.getSample(i,j,0);    
   //comparison condition
   
   Next is to display the outputImage???????

Thanks.
Try

outputImage.setData(input);
// now draw it
Avatar of hzinox

ASKER

Hi,

It does draws but the image drawn is the original image. Is it possible that I did not draw the image where it supposed to be drawn onto? I have an ImagePanel class to display modified image of type Image and ImageIcon..I do not faced any problem in displaying them. The ImagePanel class as below

public ImagePanel() {}
        public ImagePanel(ImageIcon image)
        {
                this.imageIcon = image;
                this.setSize(this.getImageHeight(),this.getImageWidth());
        }
        public ImagePanel(Image image)
        {
                this(new ImageIcon(image));
        }

        public void paintComponent(Graphics g)
        {
                super.paintComponent(g);
                if (imageIcon != null)
                {
                 int height = imageIcon.getIconHeight();
                 int width = imageIcon.getIconWidth();
                 g.drawImage(this.getImage(),0,0,this);
                }
        }
        public void setImage(ImageIcon image)
        {
                this.setImage(image.getImage());
        }
        public void setImage(Image image)
        {
                this.imageIcon = new ImageIcon(image);
                this.setSize(this.getImageHeight(),this.getImageWidth());
                //repaint();
        }
        public int getImageHeight()
        {
                if (imageIcon == null)
                {
                        return -1;
                }
          return imageIcon.getIconHeight();
        }
        public int getImageWidth()
        {
                if (imageIcon == null)
                {

                   return -1;
                }
          return imageIcon.getIconWidth();
        }

        public Image getImage()
        {
                return this.imageIcon.getImage();
        }
        private ImageIcon imageIcon = null;

Any help is welcome.
Thanks.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial