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

  • SEARCH
  • Home
  • 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 6677453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:07:19+00:00 2026-05-26T04:07:19+00:00

I have some NDK based C++ code that needs to build an android bitmap

  • 0

I have some NDK based C++ code that needs to build an android bitmap object. I’m sure there is a way to do this directly from the C++ code but its not the easiest of things to do 😉

So the method I want to call is

Bitmap.createBitmap( width, height, Bitmap.Config.ARGB_8888 );

So to do this from native code I need to do the following steps.

  • Find the class (android.graphics.Bitmap).
  • Get the static method id of “createBitmap”.
  • Create the enum.
  • Call the static method.

(Eventually I will need to create a jintArray and pass the data in but I’ll worry about that later).

I’m very lost on steps 2 and 3 though. My code looks like this at the moment:

jclass      jBitmapClass        = gpEnv->FindClass( "android.graphics.Bitmap" );
jmethodID   jBitmapCreater      = gpEnv->GetStaticMethodID( jBitmapClass, "createBitmap", "(IILandroid/graphics/Bitmap/Config;)Landroid/graphics/Bitmap;" );

but then I’m stuck. How do I create an enum from native C/C++ code?

Furthermore is my last parameter into GetStaticMethodID correct? I wasn’t sure how to specify the specific objects but I think the above works. May be wrong on the enum, though!

Thanks in advance.

  • 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-26T04:07:20+00:00Added an answer on May 26, 2026 at 4:07 am

    I have this in my code, so I can give you answer that works.

    1) Get the static method id of createBitmap(int width, int height, Bitmap.Config config):

    jclass java_bitmap_class = (jclass)env.FindClass("android/graphics/Bitmap");
    jmethodID mid = env.GetStaticMethodID(java_bitmap_class, "createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
    

    Note signature of Bitmap.Config, it has $ sign in it.

    2) Creating enum for Bitmap.Config with given value:

    const wchar_t config_name[] = L"ARGB_8888";
    jstring j_config_name = env.NewString((const jchar*)config_name, wcslen(config_name));
    jclass bcfg_class = env.FindClass("android/graphics/Bitmap$Config");
    jobject java_bitmap_config = env.CallStaticObjectMethod(bcfg_class, env.GetStaticMethodID(bcfg_class, "valueOf", "(Ljava/lang/String;)Landroid/graphics/Bitmap$Config;"), j_config_name);
    

    Here we create Bitmap.Config enum from named value. Another possible value string is “RGB_565”.

    3) Calling createBitmap:

    java_bitmap = env.CallStaticObjectMethod(java_bitmap_class, mid, w, h, java_bitmap_config);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some automatic de-serialization code that will set an object's properties using KVC
I have some image processing Java code in Android that acts upon two large
Have some text that needs to be replaced, searched around this website for all
I'm trying to debug some native code I built using the android ndk-build script
I have some code like this in a winforms app I was writing to
I have some javascript code that is used in a few different pages in
I am trying to port some c++ code to my android application using NDK.
I'm testing some functions with Android, JNI and NDK. I have the following JAVA
I have an Android app that includes a C library using NDK to execute
I have some code that should remove the parent row of the clicked td

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.