【发布时间】:2013-04-19 03:19:55
【问题描述】:
我正在尝试从 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 为空?
【问题讨论】:
标签: java android bitmap buffer