I am looping through a few png's to create an animation for a java splashscreen.
I start the animation using this
java -splash:images/anim.png SplashDemo
and use the pngs inside the class . You can find the class here- http://pastebin.com/UWm25QfY
My only problem is whatever alpha I choose to start the animation using anim.png is final and is being overwritten for all the pngs later
I tried the AlphaComposite.Clear,Src,SrcOver but nothing worked. If I load a png iniatially with 0 opacity then the entire animation disappears. Could anyone tell me how to get rid of this?
So, the problem you are facing has to do with the fact that the
Graphics
context you are painting is never actually "cleaned" or "rest" between updates. Which is a pain, I know, but there it is.About the only choice you have is to actually reset the output on each cycle, before you paint the next image.
Lucky for use,
SplashScreen
actually provides theURL
to background image. This allows us to load the image ourselves and repaint onto the surface as we need.You should also make all best efforts to restore the
Graphics
context to the state you found it (except for what ever you painted on it of course). This can be eaisly done by making a copy of the graphics state before you paint to it...Updated with a different approach
Basically, as the size of the image increases, the speed of the update decreases. Instead, I would simply create your own so you can better control the update process.
This uses an a
JWindow
as the base window and a customisedJPanel
as the main display.It also converts all the images to "device compatiable" images, meaning they should render faster as their color pallette's don't need to be converted on the fly.
The background image was 1563x1250 and the face images are 300x300 (with varying alpha levels).
Use this example, I got a steadily update without issue, using the same images with the
SplashScreen
, it was pretty horrible...