In the Android NDK there is a library named JNI Graphics. What is that? Can I use that to load Images for OpenGL ES with C/C++?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
jnigraphicslibrary can be used to access bitmap buffers in C/C++ from theandroid.bitmap.Graphicsclass (in Java, of course).It’s briefly mentioned in the NDK documentation, as well as the
bitmap.hheader docs.It can be used to load images for e.g. OpenGL ES in C/C++, but you have to do some work to hand a
jobjectto that library so it can give you direct access to a buffer. You can pass that buffer to OpenGL viaglTexImage2D().First, you need a Java
Bitmapobject, which you can acquire and pass to your native method like this:That native method can look something like this:
Keep in mind you should call
AndroidBitmap_unlockPixels()when you are done with the pixel buffer, and that this example doesn’t check for errors at all.Update for Sid Datta’s question: You can ensure that the output image format is what you’re expecting by adding this to options above:
There is one case where the output image will still end up with an unknown format in JNI. This seems to happen only with GIFs. After calling
BitmapFactory.decodeResource(), you can convert the image to the proper format if necessary: