0

I wrote some JNI to run on Android, it works great except its crashing on the last line. So I was wondering if you can please see if I am using getPixels correct. Documentation for getPixels: http://developer.android.com/reference/android/graphics/Bitmap.html#getPixels%28int%5B%5D,%20int,%20int,%20int,%20int,%20int,%20int%29

This is my full code: https://gist.github.com/Noitidart/cb6e7c3a102784d04262

This is the relavent parts:

var bmp = Bitmap.createBitmap(width, height, Bitmap_Config.ARGB_8888);

var rgba = JNI.jint.array(4 * width * height)();

bmp.getPixels(
    rgba,
    0,
    width * 4, // stride
    0,
    0,
    width,
    height
);

I'm unsure if I am setting right size to my rgba array, and if I set the stride right. I did width * 4 for stride because rgba is 4 numbers per pixel. And thats also why I did width * 4 * height for the size of the rgba array.

Please advise

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    get rid of all `4 *` ... int itself is "byte * 4" – Selvin Jul 16 '15 at 08:44
  • Thanks @Selvin for that verification, I tried that but it still crashes. :( If I comment out `bmp.getPixels....` then it doesnt crash :( – Noitidart Jul 16 '15 at 08:45
  • 1
    define crashes ... also what language ? `var` is neither Java nor C/C++ – Selvin Jul 16 '15 at 08:48
  • Thanks @Selvin for your fast replies, language is javascript ([js-ctypes docs](https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes)), i didn't tag it with jsctypes though because no one in that tag will be able to help. I am making an addon for firefox browser for android. By crash, firefox shutsdown unexpectedly (right away). – Noitidart Jul 16 '15 at 08:48
  • 1
    What is the corresponding stacktrace? `rgba` size should be `width * height`. And are you sure about the stride value? If you created the bitmap yourself you should know the stride value. But generally, it is equals to the `width` – Simon Marquis Aug 22 '15 at 16:03
  • Thanks very much @SimonMarquis I actually fixed this up, i wasn't allocating my buffer right. Here's the fixed up code: https://gist.github.com/Noitidart/cb6e7c3a102784d04262 – Noitidart Aug 22 '15 at 23:09

0 Answers0