'BitmapFactory.decodeFile returns null with inJustDecodeBounds set to false
In my android app I am trying to create a Bitmap file from path.
Here is the path
localImagePath = "/storage/emulated/0/Hootout/HootImages/Profilepic/user_profile_photo.jpg"
Here is code for creating bitmap.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(localImagePath, options);
The bitmap file always turns out to be null.
What other things can I try?
Solution 1:[1]
First, create a bitmap from file path
File imgFile = new File("/storage/emulated/0/Hootout/HootImages/Profilepic/user_profile_photo.jpg");
if(imgFile.exists()){
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath(),bmOptions);
bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true);
imageView.setImageBitmap(bitmap);
}
I think you are giving the wrong file path. Let me know if any error again.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | abby |