问题描述
我正在使用HelloAR sample application。该示例使用ARCore。我正在Android三星galaxy Tab S5e上运行示例。
我正在尝试以编程方式拍摄屏幕截图。我知道ScreenRecorder,所以不想使用这种方法。
因此,在HelloAR示例应用程序的public void onDrawFrame(GL10 gl)
函数内部,我调用了一个自定义函数来截取屏幕截图:
View rootView = getwindow().getDecorView().getRootView();
public void createBitmapFromGLSurface() {
ByteBuffer buffer = ByteBuffer.allocate(rootView.getWidth() * rootView.getHeight() * 4);
GLES20.glreadPixels(0,rootView.getWidth(),rootView.getHeight(),GLES20.GL_RGBA,GLES20.GL_UNSIGNED_BYTE,buffer);
String filename = "SOME PATH TO SD CARD";
Bitmap bitmap = Bitmap.createBitmap(rootView.getWidth(),Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);
storeAsync(bitmap,filename);
}
从上面的代码中可以看出,我调用storeAsync
将位图写入磁盘上的单独线程中:
public static void storeAsync(Bitmap bitmap,String fileName){
AsyncTask.execute(new Runnable() {
@Override
public void run() {
File file = new File(fileName);
try {
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG,85,fOut);
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printstacktrace();
}
}
});
}
这可以工作一段时间并将图像写入磁盘,但随后我的应用程序仅关闭-它不会引发任何异常。但是,我经常在LogCat中看到如下消息:
2020-09-04 18:11:01.106 10746-10785/com.google.ar.core.examples.java.helloar W/es.java.helloa: JNI critical lock held for 19.723ms on Thread[19,tid=10785,Runnable,Thread*=0x7d232c8400,peer=0x13e82018,"GLThread 6847"]
如果我注释掉storeAsync
并且不写入磁盘,但仍然收到JNI critical lock held for...
消息,这似乎很好用。
可能是什么原因,我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)