Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4347438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:18:23+00:00 2026-05-21T12:18:23+00:00

In the Android NDK there is a library named JNI Graphics. What is that?

  • 0

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++?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:18:23+00:00Added an answer on May 21, 2026 at 12:18 pm

    The jnigraphics library can be used to access bitmap buffers in C/C++ from the android.bitmap.Graphics class (in Java, of course).

    It’s briefly mentioned in the NDK documentation, as well as the bitmap.h header 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 jobject to that library so it can give you direct access to a buffer. You can pass that buffer to OpenGL via glTexImage2D().

    First, you need a Java Bitmap object, which you can acquire and pass to your native method like this:

    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
           ...
    
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;
    
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
                                                 R.drawable.myimage, options);
    
    MyJniMethod(bitmap); // Should be static in this example
    

    That native method can look something like this:

    #include <android/bitmap.h>
    
    void MyJniMethod(JNIEnv *env, jobject obj, jobject bitmap) {
    AndroidBitmapInfo  info;
    uint32_t          *pixels;
    int                ret;
    
    AndroidBitmap_getInfo(env, bitmap, &info);
    
    if(info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
      LOGE("Bitmap format is not RGBA_8888!");
      return false;
    }
    
    AndroidBitmap_lockPixels(env, bitmap, reinterpret_cast<void **>(&pixels));
    
    // Now you can use the pixel array 'pixels', which is in RGBA format
    
    }
    

    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:

    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    

    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:

    if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
        Bitmap reformatted_bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
        bitmap.recycle(); /* reduce memory load in app w/o waiting for GC */
        bitmap = reformatted_bitmap;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to use the VertexArray with Android NDK for a project that already
How can I build libsdl using the Android NDK's standalone toolchain? I can't use
I have a shared library that I build with the Android NDK, which ends
Are there any decent Android NDK examples and tutorials out there? Where can I
I'm beginning with android NDK. I have to compile a native library for the
I want to have a full documentation for android ndk. or a url that
I try to run my project in windows. Project use android ndk. I install
Can anybody help me on how to use speex or jspeex in android? I
I would like to use cURL library in my android application in native code
Under Android NDK, is there a sleep() function which sleeps for X miliseconds, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.