I have a image stored in SD card of my phone. I want to show it in a image view. I know the location of the file. On the oncreate of the activity is there a simple way to say something like
ImageView img = (ImageView) findViewById(R.id.imageView1);
String path = Environment.getExternalStorageDirectory().toString() "Images/image.jpg";
img.setsrc = path ;
Please let me know if there is any way to do this. Thank you.
Bitmap bmp = BitmapFactory.decodeFile(pathName);
ImageView img;
img.setImageBitmap(bmp);
Hope this helps.
I have this snippet that may help:
File imageFile = new File("/sdcard/example/image.jpg");
if(imageFile.exists()){
ImageView imageView= (ImageView) findViewById(R.id.imageviewTest);
imageView.setImageBitmap(BitmapFactory.decodeFile(imageFile.getAbsolutePath()));
}
:)
Related
I have in my phone two folders Card and Phone. I create folder MyPhone in the folder Card and added in her an image flap.png. This image I want to show in the element ImageView. I want to use this variant. What am I doing wrong? Thank you.
button1.setOnClickListener {
var intent: Intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(Uri.parse("/mnt/sdcard/MyPhoto/flap.png"),"image/*")
imageView1.setImageURI(intent.data)
}
if you want only this image you can use below code
File imgFile = new File("/mnt/sdcard/MyPhoto/flap.png");
if(imgFile.exists()){
Bitmap bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView1.setImageBitmap(bm);
}else{
Log.e("tag","FILE NOT EXIST")
}
after clicking on a button and taking a picture, I want to display it in an imageview as in the following:
Bitmap bMap = BitmapFactory.decodeFile(path);
ImageView myImage1 = (ImageView) findViewById(R.id.ivReturnedPic);
myImage1.setImageBitmap(bMap);
This works great the first time you take a picture, the picture displays fine on the screen. But if I click on the button again to take a second picture, it just errors out on the phone. Emulator seems to work fine, so I have no error message to share with you. Do you think ADB bridge might be helpful in this case ? Now, if I comment out the following piece of code, no error:
myImage1.setImageBitmap(bMap);
May be because bMap is null ? Can someone help me in this issue ?
Check if bMap is null or not before assigning to ImageView
so try this
Bitmap bMap = BitmapFactory.decodeFile(path);
ImageView myImage1 = (ImageView) findViewById(R.id.ivReturnedPic);
if(bMap!=null)
{
myImage1.setImageBitmap(bMap);
}
else
{
Log.d("Checking Bitmap","bMap is null");
}
I am trying to get the image from sdcard to display it in an imageview in android. Its showing error as SkImageDecoder:factory returned null in android emulator2.2. Here is my code to retrieve image from SDcard to imageview in android.
File imgFile = new File("/sdcard/wm.png");
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageView1);
myImage.setImageBitmap(myBitmap);
}
Please resolve this issue.
Use Environment.getExternalStorageDirectory() or Environment.getExternalStoragePublicDirectory instead of hard coding the path of the sd card (i.e "/sdcard/wm.png").
I am trying to display a .jpg from my sd card into an imageview in my layout. I dont get any errors, but nothing gets displayed. I would appreciate any help. Thanks
EDIT:
layout1 = (LinearLayout) findViewById(R.id.layout1Activity);
String imgFile = Environment.getExternalStorageDirectory() + "/Apple.jpg";
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile);
ImageView myImage = new ImageView(this);
myImage.setImageBitmap(myBitmap);
layout1.addView(myImage);
do NOT access the SD card directly, try accessing it trough Environment. Like this:
String imageDir = Environment.getExternalStorageDirectory()+"/apple.jpg";
and then you can call BitmapFactory:
Bitmap myBitmap = BitmapFactory.decodeFile(imageDir);
Initially I created a bitmap from an external URL by using a bitmapFactory. I then put the bitmap in an Image view, like:
ImageView mim = (ImageView) findViewById(R.id.moviepix);
String mi = "http://xxxxxxx.com/"+ result.movie_pix;
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(mi).getContent());
mim.setImageBitmap(bitmap);
Now I need to reverse engineer the url from the ImageView.
All help is appreciated.
You can't, but you can however store the URL for later use with ImageView.setTag()