SkImageDecoder:factory returned null - android

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").

Related

Don't show image in ImageView

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")
}

How to set the image to image view that is downloaded to your application in android local

I have a image downloaded locally in application
/data/data/com.starboard.stella/files/Stella/FragranceFinder/QuestionImages/option1_woman.png
How do I access the image to set for image view?
you can use Picasso for that
Picasso.with(context).load(new File(...)).into(imageView);
refernce: http://square.github.io/picasso/
Creating a File type using your filepath, creating a Bitmap out of that File and setting the Image bitmap of your ImageView using setImageBitmap is probably the best way to go.
Paresh Mayani gives a great solution with code here: https://stackoverflow.com/a/4182060/5920187
To load an image
File imgFile = new File(pathToPicture);
Bitmap bitmap = BitmapFactory.decodeFile(pathToPicture);
then
imageView.setImageBitmap(bitmap);
I think you should try this:
try {
File file = new File(getExternalFilesDir(null) + "/Stella/FragranceFinder/QuestionImages/", "option1_woman.png");
Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(file));
ImageView image =(ImageView)findViewById(R.id.image);
image.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}

Displaying image from gallery in Oncreate method without opening gallery intent

I know how to open gallery intent and to display in the imageview.
But I am facing problem in selecting image automatically in oncreate method and display in the imageview.
I have an image in gallery folder with name "myfile.jpg"
Can anyone guide me how to do it without openting gallery intent.
Thank you in advance
Here is solution :
ImageView image = (ImageView)findViewById(R.id.myImage);
File root = Environment.getExternalStorageDirectory();
String path = root.getAbsolutePath();
path = path + File.separator + "myfile.jpg"; //where you image file located
Bitmap myBitmap = BitmapFactory.decodeFile(path);
image.setImageBitmap(myBitmap);

Android: Displaying .jpg image from sdcard using ImageView

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);

Set Imageview to show image in sdcard?

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()));
}
:)

Categories

Resources