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 7986493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:52:12+00:00 2026-06-04T11:52:12+00:00

I’m testing performance for manipulating Bitmap pixels on the JNI layer using OpenCv. Two

  • 0

I’m testing performance for manipulating Bitmap pixels on the JNI layer using OpenCv.

Two options:
1. Pass array of integers, manipulate the pixels and write pixels back to Bitmap. [41ms]
2. Pass the entire Bitmap. [35ms]

I noticed that it’s about 5ms faster to pass the Bitmap than passing the pixel array and assigning the array to a Bitmap.

The problem is that using option 2 I’m loosing the blue color and getting an orange color in place of the blue I’m expecting. The image is ARGB and it seems like its changed to RGBA? What could be the issue?

Method 1:
Java

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

int[] rgba = new int[width*height];

mSmasher.loadImage(imagePath, rgba, 0);

out.setPixels(rgba, 0, width, 0, 0, width, height);

JNI

JNIEXPORT void JNICALL Java_com_vblast_smasher_Smasher_loadImage
    (JNIEnv *pEnv, jobject obj, jstring jFilePath, jintArray jbgra, jint options)
{
    jint*  _bgra = pEnv->GetIntArrayElements(jbgra, 0);
    const char *filePath = pEnv->GetStringUTFChars(jFilePath, 0);

    if (NULL != filePath)
    {
        // init our output image
        Mat bgra(outputHeight, outputWidth, CV_8UC4, (unsigned char *)_bgra);

                // bgra image manipulations
    }

    pEnv->ReleaseIntArrayElements(jbgra, _bgra, 0);
    pEnv->ReleaseStringUTFChars(jFilePath, filePath);
}

Method 2:

JNIEXPORT void JNICALL Java_com_vblast_smasher_Smasher_getLayersBitmap
    (JNIEnv *pEnv, jobject obj, jobject bitmap)
{
    int ret;
    AndroidBitmapInfo  info;
    void*              pixels = 0;

    if ((ret = AndroidBitmap_getInfo(pEnv, bitmap, &info)) < 0) {
        LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
        return;
    }

    if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888 )
    {
        LOGE("Bitmap format is not RGBA_8888!");
        return;
    }

    if ((ret = AndroidBitmap_lockPixels(pEnv, bitmap, &pixels)) < 0) {
        LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
    }

    // init our output image
    Mat mbgra(info.height, info.width, CV_8UC4, pixels);

    mLayers[0].copyTo(mbgra);

    AndroidBitmap_unlockPixels(pEnv, bitmap);
}

Solution 05/23:
The problem was that when using an array of integers and passing it to the JNI the byte order is changed from ARGB (java) to BGRA(native). This was fine for working with the pixels. However passing the actual Bitmap object when locking the pixels the byte order didn’t change so it required to change it after modifying the pixel data.

cvtColor(mbgra, mbgra, COLOR_BGR2RGBA, 4); 
  • 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-06-04T11:52:13+00:00Added an answer on June 4, 2026 at 11:52 am

    Opencv order is BGR not RGB. I’m gonna guess the A is in the right place (or you would be seeing translucent image), but blue and red would swap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

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.