我有位图,我应该在 c++ 和 Java 方面进行操作。因此,根据这篇文章,我在 C++ 中分配了缓冲区并将引用传递给 Java。在 Java 中,我使用copyPixelsToBuffer方法从位图填充缓冲区。当我尝试从该缓冲区创建位图(没有任何操作)时,decodeByteArray返回 null。而且我不明白我的错误是什么。在我使用的代码下方。
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);
任何意见和建议表示赞赏。