Assists icon indicating copy to clipboard operation
Assists copied to clipboard

连续截屏java.lang.NullPointerException: it.acquireLatestImage() must not be null

Open chxip opened this issue 3 months ago • 1 comments

fun takeScreenshot2Bitmap(): Bitmap? { imageReader?.let { val image: Image = it.acquireLatestImage() try { val bitmap = imageToBitmap(image) return bitmap } catch (e: Throwable) { return null } finally { image.close() } } ?: let { throw RuntimeException("Please request permission for screen recording first") } }

连续截屏时acquireLatestImage会来不及填充下一帧,返回null,此处会NullPointerException 建议改成: fun takeScreenshot2Bitmap(): Bitmap? { imageReader?.let { var image: Image? = null try { image = it.acquireLatestImage() val bitmap = imageToBitmap(image) return bitmap } catch (e: Throwable) { return null } finally { image?.close() } } ?: let { throw RuntimeException("Please request permission for screen recording first") } }

chxip avatar Oct 24 '25 02:10 chxip

@ven-coder 大佬,#15 第二条有提到,但是没有修改

devlei115 avatar Oct 31 '25 14:10 devlei115