Recently, I have taken java and now am heading into Android Java.
However, Android has quite a few different things to tackle when programming.
So as my title says, how can I Import an image from my /res folder and paint it on the screen?
Usually, I would do something like this.
import java.awt.*
And in main class
public Image img;
And in public void paint
case CASE:
g2d.drawimage(...)
break
This doesn't seem to work in android.
Can someone explain how you could import and display images in a location in android?
It's great to see someone new trying out android development.
As for your question you could use and ImageView though if you are looking for something more dynamic then you should use a canvas. It will allowing for drawing images and animations.
I highly recommend you check out these tutorials:
Here is a list of 200 android tutorials that really helped me start out. Though some go over features that are now deprecated.
Android Tutorials
Here is where the videos start going over basic game making. It goes from video #61 to about #80.
Android Tutorial #61
These videos can help you draw a basic image or make a simple game if that's what your looking for. Though I recommend you go learn as much of the basics as you can before going into anything really complicated.
Don't overextend yourself with something to difficult to begin with because it migh leave your frustrated with the entire android concept.
Hope this helps.
u can add images/picture in the res/drawables
http://developer.android.com/guide/topics/graphics/2d-graphics.html
Also different devices use different resolutions
http://developer.android.com/guide/practices/screens_support.html
use a ImageView widget to display the image
image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.android);
this is assuming you have a file name android.png|jpg|gif etc in your drawable folder. If you want to use a image that is selected at runtime check here. How to set the image from drawable dynamically in android?
Related
I'm doing a card matching game at the moment and I am fairly new to Android studio so forgive me if this is a stupid question. I'm at the point where i am trying to compare two image views to see if they have the same image source.
While i'm able to do this to set the image source
ImageView obImg = findViewById(R.id.ivCard2);
obImg.setImageResource(R.drawable.AceS);
After searching around for a while i'm not sure how to get that image resource
//there's nothing simple like
obImg.getImageResource;
//and this seems to crash my program
obImg.getTag();
Thanks for everyone's help in advance
I am new on this community and i have no idea what I have to search for. So I hope there is no thread like this.
I want to create a java Android App in Android Studio where I can open a floor plan(image) and insert icons(images). If i click once on the icon it should be movable and the size of the icons should be adjustable with a seekbar.
I googled for these functions and the only thing I found was that:
https://developer.android.com/guide/topics/graphics/2d-graphics.html
Can someone tell me which is the best way to do that?
You can use normal ImageViews https://developer.android.com/reference/android/widget/ImageView.html
with events (OnClick, OnTouch).
If you want to resize view, check this answer
-https://stackoverflow.com/a/14283837/8180966
For rotation
//#param rotation The degrees of rotation.
imageView.setRotation(float rotation);
If you want your icons to look nice at any size, you should look at Vector Graphics (https://developer.android.com/studio/write/vector-asset-studio.html)
Hope, this will help :)
You may please visit the following page (especially layer list section of the page) of android developer site. There are a few things which you may be interested in and which may serve either as a solution or an alternative to your problem.
https://developer.android.com/guide/topics/resources/drawable-resource.html
I created a surfaceVeiw with a custom Background and a little figure. So far so good. Is there a posibility to show a Explosion (not as one picture but as a little video) when the figure collides with objects?
I already created these objects so the only thing I need to know is, how I can implement a method to show such explosion.
Do you need some code to help me?
You can use glide libray for showing gif in android
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading_gif)
.into(imageView);
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.
We are developing simple arcade game for android now and we are interested in adding some visual effects to it. Like disappearing or appearing animation and so on. Is there a simple way to do it without OpenGL for example just using some improvements to ImageView?
You could use the BitmapFactory and Bitmap Class to perform simple manipulations on images. Check out the http://developer.android.com/reference/android/graphics/Bitmap.html for what you can do with this class. It supports simple stuff like reloading, fading out, creating ScaledMaps and manipulating images on the screen on basic level.
For some simple instructions and examples see:
http://developer.android.com/guide/topics/graphics/index.html
http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
Chapter 6 in "Android Developers cookbook" : http://www.informit.com/store/product.aspx?isbn=0321741234