mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 4);
mVirtualDisplay = mMediaProjection.createVirtualDisplay(TAG, mWidth, mHeight, mDPI,DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mImageReader.getSurface(), getimg(), null);
image = mImageReader.acquireLatestImage();
12-14 13:57:06.893:W / System.err(15177):java.lang.RuntimeException: ImageReaderContext未初始化12-14 13:57:06.927: W / System.err(15177):at android.media.ImageReader.nativeImageSetup(Native Method)12-14 13:57:06.961:W / System.err(15177):at android.media.ImageReader.acquireNextSurfaceImage(ImageReader.java:298) 12-14 13:57:06.992:W / System.err(15177):at android.media.ImageReader.acquireNextImage(ImageReader.java:344)12-14 13:57:07.024:W / System.err(15177):at com.zed1.luaservice.ScreenService.acquireLatestImage(ScreenService.java:109) 12-14 13:57:07.056:W / System.err(15177):at com.top.colour.ColorUtil.snap(ColorUtil.java:89)12-14 13:57:07.087: W / System.err(15177):at com.top.colour.FindImageFuzzy.execute(FindImageFuzzy.java:55)12-14 13:57:07.111:W / System.err(15177):at org.keplerproject.luajava.LuaState._call(Native Method)12-14 13:57:07.138:W / System.err(15177):at org.keplerproject.luajava.LuaState.call(LuaState.java:602)12-14 13:57:07.165:W / System.err(15177):at com.zed1.server.LuaService.call(LuaService.java:33)12-14 13:57:07.193:W / System.err(15177):at com.zed1.server.LuaThread.callLua(LuaThread.java:71)12-14 13:57:07.220:W / System.err(15177):at com.zed1.server.LuaThread.run(LuaThread.java:49)
答案 0 :(得分:1)
我遇到了同样的问题,但是不是在我的设备上,而是在我的一位客户上。我在this网站上发现了东西。他们使用以下代码:
Image image;
try {
image = mImageReader.acquireLatestImage();
} catch (RuntimeException e) {
/* In API level 23 or below, it will throw "java.lang.RuntimeException:
ImageReaderContext is not initialized" when ImageReader is closed. To make the
behavior consistent as newer API levels, we make it return null Image instead.*/
if (isImageReaderContextNotInitializedException(e)) {
image = null;
} else {
throw e; // only catch RuntimeException:ImageReaderContext is not initialized
}
}
if (image == null) {
return null;
}
private boolean isImageReaderContextNotInitializedException(RuntimeException e) {
return "ImageReaderContext is not initialized".equals(e.getMessage());
}
我不知道它是否可以解决问题,因为崩溃不会在我的设备上发生。让我知道是否有帮助。