【发布时间】:2020-10-27 06:09:32
【问题描述】:
我已经使用底部代码。但它出现绿色位图 当我使用 imageproxy 仅对最新的智能手机进行位图时。 比如三星s20
底部代码在过去的设备上运行良好 谁有问题?
fun Image.toBitmap(): Bitmap {
val yBuffer = planes[0].buffer // Y
val uBuffer = planes[1].buffer // U
val vBuffer = planes[2].buffer // V
val ySize = yBuffer.remaining()
val uSize = uBuffer.remaining()
val vSize = vBuffer.remaining()
val nv21 = ByteArray(ySize + uSize + vSize)
//U and V are swapped
yBuffer.get(nv21, 0, ySize)
vBuffer.get(nv21, ySize, vSize)
uBuffer.get(nv21, ySize + vSize, uSize)
val yuvImage = YuvImage(nv21, ImageFormat.NV21, this.width, this.height, null)
val out = ByteArrayOutputStream()
yuvImage.compressToJpeg(Rect(0, 0, yuvImage.width, yuvImage.height), 50, out)
val imageBytes = out.toByteArray()
return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
}
【问题讨论】:
-
我对 android-camerax 一无所知,但您似乎以某种方式弄乱了数组的列大小。再次检查行、列、通道和步幅。
-
嗨@You.Brighton,我得到了相同的结果,但在不同的设备上,你能就这个问题提供一点帮助吗?
标签: android image bitmap android-camerax