Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Show Image in Android using Java Code

Tags:

android

I am try to show a image in android using java code not xml. I have done it using xml file but my requirement is using java code to get more funcionality .

thanks in advance for help........

like image 591
sumit Avatar asked Jan 20 '12 05:01

sumit


People also ask

Can you display images in Java?

Display an Image in Java Using JLabel. JLabel extends JComponent , and we can attach this component to a JFrame . To read the image file, we use the File class and pass the path of the image. Next we convert the image to a BufferedImage object using ImageIO. read() .

What is ImageView in android?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.

What is ImageSwitcher in android?

android.widget.ImageSwitcher. ViewSwitcher that switches between two ImageViews when a new image is set on it.


2 Answers

IF you want to load image from drawable folder, you can using:

ImageView imgView=(ImageView) findViewById(R.id.imgView);
Drawable  drawable  = getResources().getDrawable(R.drawable.img);
imgView.setImageDrawable(drawable);
like image 137
jeet Avatar answered Nov 15 '22 07:11

jeet


You have to use one default imageview in android xml when you are running app that time in activity you have to write this code so it will replace you image with another image. Check following code

ImageView imgView=(ImageView) findViewById(R.id.default_imgView);
imgView.setImageResource(R.drawable.yourimagename);
like image 43
Mr. Sajid Shaikh Avatar answered Nov 15 '22 07:11

Mr. Sajid Shaikh