缓冲区不够大,用于像素
我正在尝试从字节数组中获取一个位图
val bitmap_tmp =
Bitmap.createBitmap(height, width, Bitmap.Config.ARGB_8888)
val buffer = ByteBuffer.wrap(decryptedText)
bitmap_tmp.copyPixelsFromBuffer(buffer)
callback.bitmap(bitmap_tmp)
,我在下行中面临错误:
bitmap_tmp.copyPixelsFromBuffer(buffer)
错误读取为:
java.lang.RuntimeException: Buffer not large enough for pixels
我尝试了在堆栈上找到的其他解决方案,例如在错误之前添加行,但仍然崩溃:
buffer.rewind()
但是怪异的部分是同一图像的不同位置的相同代码[具有相同维度的同一图像]获得了完美的功能,我得到了位图,但在这里崩溃了。 我该如何解决? 感谢ADV
I am trying to get a bitmap From byte array
val bitmap_tmp =
Bitmap.createBitmap(height, width, Bitmap.Config.ARGB_8888)
val buffer = ByteBuffer.wrap(decryptedText)
bitmap_tmp.copyPixelsFromBuffer(buffer)
callback.bitmap(bitmap_tmp)
I am facing a error in the below line :
bitmap_tmp.copyPixelsFromBuffer(buffer)
The Error Reads As:
java.lang.RuntimeException: Buffer not large enough for pixels
I have tried Different Solutions found on stack Like Add the line before error but still it crashes:
buffer.rewind()
However the Weird part is the same code at a different place for the same image [Same image with same dimensions] get perfectly functioned and I get the bitmap but here it crashes.
How do I solve this?
Thanks in Adv
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息听起来像您要复制的缓冲区不够大,就像它需要在需要覆盖位图中的每个像素时至少包含至少包含设置大小和像素配置)。
该方法的文档并不清楚,但是这是位图类的来源,在这种方法中:
是的,您不能部分覆盖位图,您需要足够的数据来填充它。如果您检查源,这取决于缓冲区的当前
位置
和limit
(不仅是其容量,还需要读取多少数据)。如果它在其他地方工作,我猜
decryptedText
在那里有所不同,或者也许您正在创建bitmap
使用不同的bitmap.config
(像argb_8888
每个像素需要4个字节)The error message makes it sound like the buffer you're copying from isn't large enough, like it needs to contain at least as many bytes as necessary to overwrite every pixel in your bitmap (which has a set size and pixel config).
The documentation for the method doesn't make it clear, but here's the source for the Bitmap class, and in that method:
So yeah, you can't partially overwrite the bitmap, you need enough data to fill it. And if you check the source, that depends on the buffer's current
position
andlimit
(it's not just its capacity, it's how much data is remaining to be read).If it works elsewhere, I'm guessing
decryptedText
is different there, or maybe you're creating yourBitmap
with a differentBitmap.Config
(likeARGB_8888
requires 4 bytes per pixel)