Hi All,
I want to allocate memory in native used by bitmapfactory option
parameter, when we create bitmap.( After andorid 3.0, mem allocate in heap)
following is my code:
in java code
*Bitmap b = createBitmap(600, 600);//this is my ndk interface*
// normal
Options options = new Options();
options.inBitmap = b;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
InputStream in =
getResources().openRawResource(R.drawable.ic_launcher);
Bitmap noticeIcon = android.graphics.BitmapFactory.decodeStream(in,
null, options);
//============================================================
And,* ndk createBitmap code* is as following:
JNIEXPORT jobject JNICALL
Java_com_example_ndktest_BitmapFactory_nativeCreateBitmap(
JNIEnv * env, jobject obj, jintArray jColors, int offset, int stride,
int width, int height, SkBitmap::Config config,jboolean isMutable){
SkBitmap* bitmap = new SkBitmap();
bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
bool bAlloc = bitmap->allocPixels();
jobject javaBitmap = GraphicsJNI::createBitmap(env, bitmap,
GraphicsJNI::kBitmapCreateFlag_None, NULL);
return javaBitmap;
}
above is my point, but when i compile in android 4.4 source code, it
complain sigbus error.
I found the reason is that:
1. bitmapfactory ondecode funcition will use options to create bitmap, then
2. RecyclingPixelAllocator will allocate pixelRef by AndroidPixelRef.
AndroidPixelRef::AndroidPixelRef(AndroidPixelRef& wrappedPixelRef,
SkColorTable* ctable) :
SkMallocPixelRef(wrappedPixelRef.getAddr(),
wrappedPixelRef.getSize(), ctable, false),
fWrappedPixelRef(wrappedPixelRef.fWrappedPixelRef ?
wrappedPixelRef.fWrappedPixelRef : &wrappedPixelRef)
3. I found wrappedPixelRef.fWrappedPixelRef is not null, so
wrappedPixelRef.fWrappedPixelRef used then error happend.
I used wrappedPixelRef is OK
Is there any method to modify ndk code so that make
wrappedPixelRef.fWrappedPixelRef is null, then my test will be ok? thank
you.
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/2bad3077-6f4d-4110-8aa1-4e1f2a0dd1ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.