Hi, I am trying to convert an image into grey scale. I can do this using a buffered image however the image type I have is Image. As you can see in the code below I try to cast the Image to a BufferedImage, apply the greyscale then cast is back to an Image.

MemoryImageSource src = new MemoryImageSource(grabbing.getWidth(), grabbing.getHeight(), intArr, 0, grabbing.getWidth());
        Image imageto = label.createImage(src);
        BufferedImage buff = (BufferedImage) imageto;
        Image grayImage = (Image)createGrayscalePic(buff);
        ImageIcon im = new ImageIcon(grayImage);
        label.setIcon(im);
        frame1.getContentPane().add(label, BorderLayout.CENTER);
        frame1.pack();
        frame1.setVisible(true);

However I get an exception:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.awt.image.ToolkitImage

and the line that causes this exception is :

BufferedImage buff = (BufferedImage) imageto;

Does anyone have any ideas how I can solve this problem.
Thanks

The is the method that converts a buffered image to greyscale:

public BufferedImage createGrayscalePic(BufferedImage raw) {
        BufferedImage temp = new BufferedImage(raw.getWidth(), raw.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
        temp.getScaledInstance(WIDTH, WIDTH, WIDTH);
        Graphics g = temp.getGraphics();
        g.drawImage(raw, 0, 0, null);
        g.dispose();

        return temp;
    }

can any one tell me how to blur an image in java...( i want the code..)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.