I am loading a number of images in application using BitmapFactory.decodeFileDescriptor.But decodeFileDescriptor wants filedescriptor.decodeFileDescriptor as the argument.I want to load image from assets.So I am using asset manager to get path to asset folder.I know that I can get filedescriptor through fileinputstream.But return type of asset manager open method is input stream so I have to use inputstream.Even I cannot find a way to get fileinputstream from inputstream.So How do I get filedescriptor from inputstream.Thanks for help
Asked
Active
Viewed 1,709 times
1
-
What is wrong with the `decodeStream()` method on `BitmapFactory`? – CommonsWare Mar 21 '15 at 17:17
-
I am getting out of memory exception while using decodestream as I have to load a lot of image for animation.I have read that for many images one should use BitmapFactory.decodefiledescriptor. – Ronak Mar 21 '15 at 17:25
-
Since an asset is merely an entry in a ZIP archive, I will be rather surprised if there is a way to get a `FileDescriptor` for it. Beyond that, I will be **very** surprised if this matters at all in terms of your memory usage. – CommonsWare Mar 21 '15 at 17:26
-
I am getting this error for memory out of exception http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object – Ronak Mar 21 '15 at 17:30
-
That is because you do not have a big enough block of memory for whatever it is that you are trying to do. This is common when dealing with lots of bitmaps, regardless of where the bitmaps come from. [This answer](http://stackoverflow.com/a/10127787/115145) is about the only one on that question that is worthwhile on its own. Some of the others have useful tidbits (e.g., `inBitmap`, `inSampleSize` on `BitmapFactory.Options`). I delivered [a presentation at the Samsung Developer Conference](http://commonsware.com/videos) last year that covers memory management. – CommonsWare Mar 21 '15 at 18:07
1 Answers
0
You should use openFd instead.Something like this.
AssetFileDescriptor blah = mainActivity.getResources().getAssets().openFd("acme.png");
FileDescriptor fd = blah.getFileDescriptor();
Hope it helps!

ERic
- 21
- 4