When I am calling this function there is no image in image view
bitmapFactory.decodefile(filename)
showing null .. please help for this.
Here is my cod
The BitmapFactory.decodeFile()
executes before the entire image placing in that exact path. When decodeFile()
executes there is no image. So the bitmap returns null
. Generally the high pixel images takes some extra time to place in their path. So this exception happens.
Please check the null and try to decodeFile.
Bitmap bitmap = null;
while(bitmap == null)
bitmap = BitmapFactory.decodeFile(imageInSD);
Delete "options.inJustDecodeBounds = true;"
if you have
val options = BitmapFactory.Options();
//options.inJustDecodeBounds = true; //delete this line
var bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
Try this code it will help you to solve your problem
Replace gallery image with gallery image in android show too large exception
Hi it is null
because may be the image size is big and getting exception please check your log and see is there any error of outofmemory bitmap if yes then use options for that:
BitmapFactory.Options options;
try {
String imageInSD = "/sdcard/UserImages/" + userImageName;
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
return bitmap;
} catch (OutOfMemoryError e) {
try {
options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD, null, options);
return bitmap;
} catch(Exception excepetion) {
Log.e(excepetion);
}
}
Be sure that in your options (BitmapFactory.Options) the InJustDecodeBounds is set to false or otherwise it will return null. This can be set to true when you just want the file to be decoded but you don't need it further in your code. This way no extra memory needs to be allocated. See here for more explanation.
My solution was to add to the manifest's Applicaiton tag:
Android: requestLegacyExternalStorage = "true"