Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 820 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 »

Hello,

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
                      transparency
     //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);

     newContext.dispose();
     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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!