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.