I have bitmap which I should manipulate both in c++ and Java sides. Therefore, according to this post I allocated the buffer in C++ and passed the reference to Java. In Java I filled the buffer from bitmap using copyPixelsToBuffer method. When I tried to create bitmap from that buffer(without any manipulations) the decodeByteArray returned null. And I don't understand what was my mistak. Below the code which I used.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
mCurrentBitmap = BitmapFactory.decodeFile(hardCodedPath, options);
// 4- bytes count per pixel
bytesCount = mCurrentBitmap.getWidth() * mCurrentBitmap.getHeight() * 4;
pixels = (ByteBuffer) allocNativeBuffer(bytesCount);
pixels.order(ByteOrder.nativeOrder());
mCurrentBitmap.copyPixelsToBuffer(pixels);
pixels.flip();
pixels.order(ByteOrder.BIG_ENDIAN);
byte[] bitmapdata = new byte[pixels.remaining()];
pixels.get(bitmapdata);
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length, opt);
Any comments and suggestions are appreciated.