BufferedImage and ImageProducer

[b][red]This message was edited by Souldrinker at 2004-9-3 6:37:44[/red][/b][hr]
Hi there!

I've tried around a bit with the ImageFilter classes of Java, and found that realy nice class RGBImageFilter. I've written a routine to change every nontransparent pixel into a certain color (it's for an isometric engine, but that is not important at this time). Now I'm stucked into the following problem:

How do I generate a BufferedImage out of an ImageProducer? The following Code leads me to a class cast exception:

[code]
ImageProducer imageprod = new FilteredImageSource( ImageSolve.getSource(), maskFilter );
Mask = (BufferedImage) Toolkit.getDefaultToolkit().createImage( imageprod );
[/code]

The "maskFilter" is my tiny filter class, that extends the RGBImageFilter. "ImageSolve" is the Image I want to change the Pixels out of, and write the black/transparent Mask into the BufferedImage "Mask", declared before.

Now I create the ImageProducer, and try to get a BufferedImage out of the Toolkits createImage routine. It's logical that this doesn't work ;)

I solved the problem by generating a Buffer, on that I write the Image, created out of the creatImage() function. But I guess there is a way to do this without a Buffer, isn't it?


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories