I am very very new at java (as in, I took one beginner course) so please don't get super technical when answering me.
Earlier today I learned how you can load an image in java and display it in an applet.
I found a step-by-step youtube video that helped me do this.
Now I want to know how I can load an animation in java. Is that something that can be done? And can I get step-by-step instructions on how to do it? Basically, I already have a short .wmv file and I would like to display it when I run the program.
It also has audio that I would like to play along with it.
(i'm actually trying to make a video game with an animated character. java can be used to program games, so this should be doable, right? i don't care about making a game the "right" way or the way game developers usually do it, right now i just want to figure out the simple task of displaying an animation in java.)
thanks!
First of all, the wmv extension stands for video, and an animation is not a video. Its either a spritesheet, a gif image ect. In order to create a even simple animation, you must first learn some basic object oriented programming, become comfortable in creating and using classes, than you can advance to making your own class for taking care of sprites and cutting an image in a way that you can use it ect.
Example of a simple spriteshet:
This spritesheet is an simple image showing you one way to implement your 2d animation. You just have to cut the image parts from it using some rectangles. For 3d, you must use some other software and you must know that they use different kinds of extensions.
I wont dive into code, for the simple reason that I do not have time right now, but if you want further help, give my some contact like skype, facebook ect, I would love to help.
You could try the Java Media Framework javax.media.*. (caveat: rather old framework)
It appears you simply need to embed a media file such as video or audio into an applet. This can be achieved through a player embedded into an applet, similar to an individual frame or a .GIF file, that would be able to handle the .WMV extension.
Assuming awareness of the basic structure of a Java program, the main declaration to get an instance of a player is of the generic form, after:
player = Manager.createRealizedPlayer( mediaURL );
or
player = Manager.createPlayer( file.toURL() );
Good idea to go through the JMF documentation.
Related
I have used Java language for beginners is used with object type calling so there's an app or software called processing that I used that's a bit easy at making programs... (https://processing.org/)
What could be the best shortest example to make a animated GIF using shapes/ images?
What way could be the best way to make a GIF animated in regular Java without using processing software?
What could be the easiest examples for a beginner to do an animated GIF?
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:
You need to break your problem down into smaller steps and then take those steps on one at a time. Can you create a simple animation? Something simple like a circle moving around the screen. Separately from that, can you export a single .png image from a sketch? Again, just something simple. Work your way forward in small steps: can you then export each frame of a simple animation as a .png file?
Then when you have those .png files, you can use something like Image Magick to convert them into an animated gif file.
The Processing reference is your best friend for questions like this. The save() and saveFrame() functions could come in handy for exporting an animation as a gif.
Please try something, and if you get stuck, post a MCVE along with a more specific technical question in a new post. Good luck.
Hi i'm looking for a way to display a Libgdx sprite batch, or something like this, without using any Application Listener, Adapter or the Game class.It should be possible to call a constructor of some gameobject and then it's texture should be displayed to a batch or some window.
The reason is, that i want to use a desktop-application-project in class with students to start programming lessons and therefore we use BlueJ. But features like the object inspector aren't working, if there's an active application thread and things like Gdx.files ends in a nullpointer exception.
In later lessons there will be an application but in the beginning that goes too far.
All my attempts with the Game class or self written ApplicationListeners weren't succesfull. I hope somebody out there has a idea.
A SpriteBacth draws to a Screen. Application Listener/Adapter and Game is needed to manage the screens. The SpriteBach assumes you have a Screen, a LibGDX Screen, not just any Screen, and does not magically know what you want it to draw on.
You cannot just instantiate an object from one library and expect it to magically work in a different library.
I fail to see the point of it even if it were to work. Either use LibGDX or don't.
You would be much better off using something like JavaFX. It is built into java and is easy to draw images and sprites to a window. You can use JavaFX to make games AND desktop applications.
I am trying to check if an image is on a program's interface. I know how to grab the program's image but I cannot figure out a way to check if the image on on the program's screen. How can I do this?
I think checking containing one image in another is a question of "computer vision", so maybe some special libraries like OpenCV can helps you.
And this question on stackoverflow could be so useful too
OpenCV Template Matching example in Android
If you want to do the checking within the same program as the one that loads the image, it should be possible by checking the user interface control properties/attributes, and also the return values of the functions/methods used to set the image. In such a situation, Computer Vision is overkill. In this case, may be you can post some of the code used for loading the image, so that others can suggest solutions.
But if you are using a different program to capture the screen and look for the image, SIFT and SURF features of OpenCV should do the job. The accuracy won't be bad in this application.
I can't understand how to animate a single figure in Java applet, while the context remains the same (for example rotate a polygon while other figures drawn remain the same).
Is there another solution besides repainting the object and the whole context? I am asking because it would be hard to have for example a number of figures that would need to be animated when clicked.
Could you please point me towards the topics I need to understand, as well maybe an example to see things more clearly?
The technology you want is sprites. There's a short intro video here and you can search the web for oodles of info about implementing them in Java.
Best reader,
I'm stuck on one of my concepts.
I'm making a program which classroom children can measure themselves with.
This is what the program includes;
- 1 webcam (only used for a simple webcam view.)
- 2 phidgets (don't mind these.)
So, this was my plan. I'll draw a rectangle on the webcamview and make it repaint itself constantly.
When the repainting is stopped by one of the phidgets, the rectangle's value will be returned in centimeters or meters.
I've already written the code of the rectangle that's repainting itself and this was my result:
(It's a roundRectangle, the lines are kind of hard to see in this image, sorry about that.)
As you can see, the background is now simply black.
I want to set the background of this JFrame as a webcam view (if possible) and then draw the
rectangle over the webcam view instead of the black background.
I've already looked into jmf, fmj and such but am getting errors even after checking my webcam path and adding the needed jar libraries. So I want to try other options.
So;
- I simply want to open my webcam, use it as background (yes live stream, if possible in some way).
And then draw this rectangle over it.
I'm thus wondering if this is possible, or if there's other options for me to achieve this.
Hope you understand my situation, and please ask if anything's unclear.
EDIT:
I got my camera to open now trough java. The running camera is of type "Process".
This is where I got the code for my camera to open: http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/
I adjusted mine a little so it'll open my camera instead.
But now I'm wondering; is it possible to set a process as background of a JFrame?
Or can I somehow add the process to a JPanel and then add it to a JFrame?
I've tried several things without any succes.
My program as it is now, when I run it, opens the measuring frame and the camera view seperatly.
But the goal is to fuse them and make the repainting-rectangle paint over the camera view.
Help much appreciated!
I don't think it's a matter of setting a webcam stream as the background for your interface. More likely, you need to create a media player component, add it to your GUI, and then overlay your rectangles on top of that component.
As you probably know from searching for Java webcam solutions in Stack Overflow already, it's not easy, but hopefully the JMF Specs and API Guide will help you through it. The API guide is a PDF and has sections on receiving media streams, as well as sample code.