Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  RGBImageFilter not always filtering  (Read 1427 times)
0 Members and 1 Guest are viewing this topic.
Offline hooble_1

Junior Newbie

Java games rock!

« Posted 2005-05-17 13:17:12 »


I have a strange problem. I made a simple RGBImageFilter that just
returns 0xFFFF0000. Thats right, it simply replaces every pixel with
a full alpha red pixel.

My problem comes when using the filter...

     //filter     - is my red filter
     //myApplet   - is the applet I'm running this from
     //original   - is an image that was loaded from a .png file and has
     //newImage   - is a BufferedImage that I created already with the
                      same dimensions as the "original" image

     newContext = (Graphics2D)newImage.createGraphics();

     Image coloredImage = myApplet.createImage(
            new FilteredImageSource(original.getSource(), filter));

     //draw the red image
     newContext.drawImage(coloredImage, 0,0, null);

     //draw the original image over top of the red background
     newContext.drawImage(original, 0,0, null);

     return newImage;

I have this replacing colors in a function, and as it turns out, calling
this repeatedly with the SAME original image, SOMETIMES results in a
red background.

Now originally I didn't have my filter just returning red, I am just doing
this to illustrate my point. I would like to know, is there some way to
make sure the call to createImage(...) has finished making the Image
before I draw it to something else?

I am using the latest java 1.5.0_03 both for development and in my browser(IE 6),
and the appletviewer does the same thing.

Here is a pic of the problem in action:

Thanks for any help you guys can provide! I don't post here much, but I'm a long time reader.
Offline tom
« Reply #1 - Posted 2005-05-17 14:24:33 »

Maybe using a  java.awt.MediaTracker will work.

Offline hooble_1

Junior Newbie

Java games rock!

« Reply #2 - Posted 2005-05-17 14:57:25 »

I have managed to make it work reliably enough that I am satisfied(for now). I guess my problem, is that I want some way to force the createImage() operation on my current thread, instead of asynchronously having to wait for an ImageObserver to get updated.

I am now using a custom ImageObserver with a synchronized function that waits until the image is finished(or a timeout). I do that by using the component.prepareImage(img, observer) function, and pass it my observer.

This is fine in my current situation because I do my image preparations before my game starts. However, if anyone were to try this approach during a rendering loop, it would devastate the performance. I would like a synchronous way to prepare the image on the current thread, so that I could use filters in a rendering loop.

I guess this whole asynchronous image loading/creating is too well rooted to hope for something different. I don't even mind the asynch image loading, it's just this component.createImage() function that is bugging me, since it seems to be the only way to use an RGBImageFilter.

It appears that my only option, if I want to do color swapping in real time, is to have bitmasks for each image so I can use drawImage routines(yak!, I don't want more resources to load over the net).

I don't know if MediaTracker will work. From the API it seems to only keep track of image loading, not other operations that need an ImageObserver(create/draw).
Pages: [1]
  ignore  |  Print  

hadezbladez (349 views)
2018-11-16 13:46:03

hadezbladez (183 views)
2018-11-16 13:41:33

hadezbladez (348 views)
2018-11-16 13:35:35

hadezbladez (85 views)
2018-11-16 13:32:03

EgonOlsen (2179 views)
2018-06-10 19:43:48

EgonOlsen (2221 views)
2018-06-10 19:43:44

EgonOlsen (1379 views)
2018-06-10 19:43:20

DesertCoockie (2012 views)
2018-05-13 18:23:11

nelsongames (1669 views)
2018-04-24 18:15:36

nelsongames (2309 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!