Android:将图像对象转换为位图不起作用

Android:将图像对象转换为位图不起作用,第1张

概述我正在尝试将图像对象转换为位图,但它返回null.image=reader.acquireLatestImage();ByteBufferbuffer=image.getPlanes()[0].getBuffer();byte[]bytes=newbyte[buffer.capacity()];Bitmap

我正在尝试将图像对象转换为位图,但它返回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:将图像对象转换为位图不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1091621.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存