使用zxing扫描二维码出现黑屏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cuiran/article/details/45197231

最近在项目中遇到一个问题,使用zxing扫描二维码发现在一个设备上出现黑屏,然后通过调试定位问题

给出的日志是

04-22 14:51:42.492: D/(4999): Surface destroy: ANDROID_NATIVE_WINDOW_MAGIC
04-22 14:51:53.862: D/LewaResources(5139): cookie name=/data/app/com.example.qr_codescan-2.apk
04-22 14:51:53.902: D/(5139): Pixel Format : GGL_PIXEL_FORMAT_RGBA_8888
04-22 14:51:53.902: D/(5139): Updating FBO content dimensions
04-22 14:51:54.112: D/CameraConfigurationManager(5139): Default preview format: 17/yuv420sp
04-22 14:51:54.112: D/CameraConfigurationManager(5139): Screen resolution: Point(800, 1216)
04-22 14:51:54.112: D/CameraConfigurationManager(5139): preview-size-values parameter: 1280x720,720x480,640x480,640x360,352x288,320x240,176x144
04-22 14:51:54.112: W/CameraConfigurationManager(5139):  screenResolution-size: 800:1216
04-22 14:51:54.112: D/CameraConfigurationManager(5139): Camera resolution: Point(800, 1216)
04-22 14:51:54.112: D/CameraConfigurationManager(5139): Setting preview size: Point(720, 480)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): error
04-22 14:51:54.122: E/MipcaActivityCapture(5139): java.lang.RuntimeException: setParameters failed
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.hardware.Camera.native_setParameters(Native Method)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.hardware.Camera.setParameters(Camera.java:1651)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at com.mining.app.zxing.camera.CameraConfigurationManager.setDesiredCameraParameters(CameraConfigurationManager.java:83)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at com.mining.app.zxing.camera.CameraManager.openDriver(CameraManager.java:130)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at com.example.qr_codescan.MipcaActivityCapture.initCamera(MipcaActivityCapture.java:135)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at com.example.qr_codescan.MipcaActivityCapture.surfaceCreated(MipcaActivityCapture.java:158)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.SurfaceView.updateWindow(SurfaceView.java:572)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.SurfaceView.access$000(SurfaceView.java:86)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:975)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1867)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:771)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.Choreographer.doCallbacks(Choreographer.java:574)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.Choreographer.doFrame(Choreographer.java:544)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:757)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.os.Handler.handleCallback(Handler.java:733)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.os.Handler.dispatchMessage(Handler.java:95)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.os.Looper.loop(Looper.java:149)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at android.app.ActivityThread.main(ActivityThread.java:5045)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at java.lang.reflect.Method.invokeNative(Native Method)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at java.lang.reflect.Method.invoke(Method.java:515)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
04-22 14:51:54.122: E/MipcaActivityCapture(5139): 	at dalvik.system.NativeStart.main(Native Method)
04-22 14:51:54.132: I/dalvikvm(5139): Total arena pages for JIT: 11
04-22 14:51:54.132: I/dalvikvm(5139): Total arena pages for JIT: 12
04-22 14:51:54.132: I/dalvikvm(5139): Total arena pages for JIT: 13
04-22 14:51:54.132: I/dalvikvm(5139): Total arena pages for JIT: 14
04-22 14:51:54.142: D/CameraManager(5139): Calculated framing rect: Rect(160, 428 - 640, 788)
04-22 14:51:54.142: I/dalvikvm(5139): Total arena pages for JIT: 15
04-22 14:51:54.152: D/zhangxianjia(5139): init runded corner
04-22 14:51:54.252: D/(5139): Surface destroy: ANDROID_NATIVE_WINDOW_MAGIC

然后思考是不是设置的 preview-size有问题 ,后来测试发现并没有问题

最后试着去掉


然后问题就解决,猜测可能是这个设备对底层做工处理。

以上只是目前的一种解决办法,但肯定不是最好的,有空还是会继续研究一下!

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页