我正在尝试从java分配直接字节缓冲区,从位图填充它并从该缓冲区创建位图。但结果我收到空值。
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.allocateDirect((int) bytesCount);
mCurrentBitmap.copyPixelsToBuffer(this.pixels);
byte[] bitmapdata = new byte[pixels.remaining()];
pixels.get(bitmapdata);
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap newBitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, (int) bytesCount, opt);
有人可以帮我理解为什么 newBitmap 为空吗?