Reputation: 116060
i'm developing an app that at some point it has a huge bitmap and it needs to use face detection on it, so i use the FaceDetector API
the face detection API has restrictions about its input bitmap:
since i need to have the original bitmap later, i've stored it into a file.
right after that i recycle the original bitmap, and load a temporary one from the file, having the right config, but sadly, it won't always work since i need to use an even width, and the original bitmap doesn't always have an even width.
i've tried telling the face detection API to use "width-1" as the width, but it didn't work. it said "java.lang.IllegalArgumentException: bitmap size doesn't match initialization". i don't even understand why it needs such a weird width restriction and why it needs the parameters of the width and height if it already has the bitmap...
what should i do?
is it possible to make it work with odd-width bitmaps , and maybe ignore a whole column of pixels?
the reason i ask this is because the bitmap is quite large, and if i clone it to a new one that has a similar size (with an even width), i can easily get OOM on some devices.
i know i can scale using JNI (similar to a post i've written some time ago,here) , but i hope i can find a better, less hardcore-way to achieve the same thing.
if there is no other way, maybe android has a JNI functions that could help ?
Upvotes: 1
Views: 919
Reputation: 1
This can be used for converting the bitmap in the required format (The bitmap must be in 565 format).
Bitmap mFaceBitmap = bitmapImage.copy(Bitmap.Config.RGB_565, true); bitmapImage.recycle(); // If you want to free memory ASAP
And to alter the width, you can try something like
mFaceBitmapWidth = mFaceBitmap.getWidth(); mFaceBitmap.setWidth(mFaceBitmapWidth - 1);
Upvotes: 0