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.

hzinoxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
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)
hzinoxAuthor Commented:
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.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

CEHJCommented:
Try

outputImage.setData(input);
// now draw it
hzinoxAuthor Commented:
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.
CEHJCommented:
>>It does draws but the image drawn is the original image.

Well i didn't comb through how you transform the image, but in my last code, 'input' will have to contain the result of the  transformation. If it doesn't, you'll have to ensure it does

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.