
我正在尝试将图像对象转换为位图,但它返回null.
image = reader.acquireLatestimage(); ByteBuffer buffer = image.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.capacity()]; Bitmap myBitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.length,null);图像本身是jpeg图像,我可以将其保存到磁盘上,我想要转换为位图的原因是因为我想在将其保存到磁盘之前进行最后的旋转.
在类BitmapFactory中进行挖掘,我看到了这一行.
bm = nativeDecodeByteArray(data, offset, length, opts);该行返回null.
进一步挖掘调试器
private static native Bitmap nativeDecodeByteArray(byte[] data, int offset, int length, Options opts);假定返回Bitmap对象,但返回null.
有技巧或想法吗?
谢谢
解决方法:
您尚未复制字节.您已检查容量,但未复制字节.
ByteBuffer buffer = image.getPlanes()[0].getBuffer();byte[] bytes = new byte[buffer.remaining()];buffer.get(bytes);Bitmap myBitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.length,null); 总结 以上是内存溢出为你收集整理的Android:将图像对象转换为位图不起作用全部内容,希望文章能够帮你解决Android:将图像对象转换为位图不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)