Bitmap is returning null from BitmapFactory.decodeFile(filename)
-
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 code : public Bitmap ShowImage(String imageName,String userImageName ) { File sdcard_mainDirectory = new File(Environment.getExternalStorageDirectory(),"UserImages").getAbsoluteFile(); File file = new File(sdcard_mainDirectory, userImageName).getAbsoluteFile(); if (file != null) { try { String imageInSD = "/sdcard/UserImages/"+userImageName; Bitmap bitmap = BitmapFactory.decodeFile(imageInSD); return bitmap; } catch (Exception e) { e.printStackTrace(); } } return null; }
-
Answer:
Why are you doing this String imageInSD = "/sdcard/UserImages/"+userImageName; I think If you get a .png file is present then just, Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); NOTE: Also check you have a Android supported image file is present in that location..
stiffler at Stack Overflow Visit the source
Other answers
It's simple: your file either is not an image or image that is not supported by Android's Bitmap implementation, or you path is invalid. See documentation for http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeFile%28java.lang.String%29: Returns the resulting decoded bitmap, or null if it could not be decoded. Usually when bitmap cannot be decoded some logs are printed to logcat. Inspect them carefully.
inazaruk
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 e) { Log.e(e); } }
kch
Related Q & A:
- How to render Bitmap into Canvas?Best solution by stackoverflow.com
- How do I convert a bitmap to vector?Best solution by Super User
- How to convert the content of a scrollView to a Bitmap?Best solution by Quora
- What is John Lewis' policy when returning an LCD with a dead pixel?Best solution by Yahoo! Answers
- What's the best way of returning damaged NIKE shoes to NIKE for another pair?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.