Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

java - Animated GIF leads to SplashScreen being null

I know this is probably close to a duplicate of this thread: Animated GIF in Splashscreen

But since it seems unanswered and I can't comment on it or anything I'm sorry to repost this but it would be awesome if someone could give me an answer.

I am making a game and this game takes quite a lot of time to start. Therefore I want to give the user feedback during the loading screen so he knows the application hasn't crashed. That's why I use the SplashScreen API from java 7.

In eclipse, when I run my application using the following configuration in VM Arguments, SplashScreen.getSplashScreen() returns null.

-splash:src/aapplication/Splash.gif

But when I use this configuration, it works fine (I have to files in the same package, one is Splash.png and the other Splash.gif):

-splash:src/aapplication/Splash.png

In a jar file (in MANIFEST.MF), this doesn't work:

SplashScreen-Image: aapplication/Splash.gif

While this does:

SplashScreen-Image: aapplication/Splash.png

My GIF is about 1Mb in size while the PNG is 50kb.

Can anyone explain to me why does the GIF can't even be loaded while the PNG does (I know it's not the path since they have the same)?

Everywhere I looked, it said it should work just as fine as for PNGs.

Thanks for your help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you'll find that the problem comes down to two things...

  1. Using the command line parameter (-splash), Java expects the image to be a file on the file system, whereas the manifest file expects it to be an embedded resource.
  2. Java doesn't seem capable of playing optimised gifs, that is gifs whose frames represent the difference between the last and current frame, instead of a complete image (as far as the splash screen goes).

I tried using

Pony01

and

Pony02

The first image failed, but the second worked, the difference, as near as I can tell, is the first is optimised and the second is not...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...