0

我正在开发一个使用相机的应用程序。我尝试了两个不同的代码,它们完成了 2 个不同的任务,在 Windows 10 上它们没有给我任何问题并且工作正常,在 android 上运行它们给了我一些问题。

第一个代码应该在我每次触摸屏幕并在屏幕上显示图片时拍照,但每次我触摸屏幕时都会出现错误Camera is not ready 提示并且屏幕上没有显示图像。

import QtQuick
import QtMultimedia

Window {
    id: main_window
    width: Screen.desktopAvailableWidth
    height: Screen.desktopAvailableHeight
    visible: true
    MediaDevices {
        id: mediaDevices
    }
    CaptureSession {
        Component.onCompleted: {
            camera.start()
        }
        id:captureSession
        camera: Camera { id: camera }
        imageCapture: ImageCapture {
            onErrorOccurred: function(requestId, error, message) {
                console.log("Error occurred:"+message+"\nCamera active:"+camera.active+"\nImage capture ready:"+captureSession.imageCapture.readyForCapture+"\n")
            }
            onImageCaptured: {
                console.log("Image captured\n")
            }
        }
    }
    Image {
        id: image
        anchors.fill: parent
        source: captureSession.imageCapture.preview
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            onClicked: {
                captureSession.imageCapture.capture()
            }
        }
    }
}

在我的手机上调试这段代码,这是我触摸屏幕一次后的输出:

E Zygote  : isWhitelistProcess - Process is Whitelisted
E Zygote  : accessInfo : 1
I tQuickAppBackU: Late-enabling -Xcheck:jni
E tQuickAppBackU: Unknown bits set in runtime_flags: 0x8000
D ActivityThread: setConscryptValidator
D ActivityThread: setConscryptValidator - put
W System  : ClassLoader referenced unknown path:
D PhoneWindow: forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4274 com.android.internal.policy.DecorView.updateColorViews:1547 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3252 android.view.Window.setFlags:1153 com.android.internal.policy.PhoneWindow.generateLayout:2474
I MultiWindowDecorSupport: [INFO] isPopOver = false
I MultiWindowDecorSupport: updateCaptionType >> DecorView@85f9c98[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
D MultiWindowDecorSupport: setCaptionType = 0, DecorView = DecorView@85f9c98[]
D Qt JAVA : Class org.qtproject.qt.android.multimedia.QtAudioDeviceManager does not implement setActivity method
I QtCore  : Start
I Qt      : qt started
I ViewRootImpl@879196a[QtActivity]: setView = com.android.internal.policy.DecorView@85f9c98 TM=true MM=false
I ViewRootImpl@879196a[QtActivity]: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=11 res=0x7 s={true 513189548032} ch=true
D OpenGLRenderer: createReliableSurface : 0x777c754940(0x777c7b1000)
D OpenGLRenderer: makeCurrent EglSurface : 0x0 -> 0x0
I mali_winsys: new_window_surface() [1080x2400] return: 0x3000
D OpenGLRenderer: eglCreateWindowSurface : 0x7771e9a700
D OpenGLRenderer: makeCurrent EglSurface : 0x0 -> 0x7771e9a700
W Gralloc3: mapper 3.x is not supported
I gralloc : Arm Module v1.0
I ViewRootImpl@879196a[QtActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D InputMethodManager: prepareNavigationBarInfo() DecorView@85f9c98[QtActivity]
D InputMethodManager: getNavigationBarColor() -855310
D InputMethodManager: prepareNavigationBarInfo() DecorView@85f9c98[QtActivity]
D InputMethodManager: getNavigationBarColor() -855310
V InputMethodManager: Starting input: tba=org.qtproject.example.FirstQtQuickAppBackUp ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D InputMethodManager: startInputInner - Id : 0
I InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
I ViewRootImpl@879196a[QtActivity]: MSG_RESIZED: frame=(0,0,1080,2400) ci=(0,93,0,126) vi=(0,93,0,126) or=1
D InputMethodManager: prepareNavigationBarInfo() DecorView@85f9c98[QtActivity]
D InputMethodManager: getNavigationBarColor() -855310
V InputMethodManager: Starting input: tba=org.qtproject.example.FirstQtQuickAppBackUp ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D InputMethodManager: startInputInner - Id : 0
I SurfaceView: onWindowVisibilityChanged(0) true org.qtproject.qt.android.QtSurface{545da3c V.E...... ......I. 0,0-0,0 #1} of ViewRootImpl@879196a[QtActivity]
I ViewRootImpl@879196a[QtActivity]: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=5 res=0x1 s={true 513189548032} ch=false
I SurfaceView: surfaceCreated 1 #8 org.qtproject.qt.android.QtSurface{545da3c V.E...... ......ID 0,0-1080,2181 #1}
I SurfaceView: surfaceChanged (1080,2181) 1 #8 org.qtproject.qt.android.QtSurface{545da3c V.E...... ......ID 0,0-1080,2181 #1}
I mali_winsys: new_window_surface() [1080x2181] return: 0x3000
I OpenGLRenderer: doUpdatePositionAsync is called and callVoidMethod
D InputMethodManager: HSIFW - flag : 0
I InputMethodManager: hideSoftInputFromWindow ignore mServedView == null or mServedView.getWindowToken() != windowToken, mServedView :DecorView@85f9c98[QtActivity]
I ViewRootImpl@879196a[QtActivity]: ViewPostIme pointer 0
I ViewRootImpl@879196a[QtActivity]: ViewPostIme pointer 1
D qml     : : Error occurred:Camera is not ready.
D qml     : Camera active:false
D qml     : Image capture ready:false
12-15 18:36:29.681  7941 10018 D qml     :

第二个代码应该显示来自相机的实时图像,它符合我的预期,但应用程序输出包含递归错误W OpenGLRenderer: [SurfaceTexture-0-9089-0] bindTextureImage: clearing GL error: 0x500

import QtQuick
import QtMultimedia

Window {
    id: main_window
    width: Screen.desktopAvailableWidth
    height: Screen.desktopAvailableHeight
    visible: true
    MediaDevices {
        id: mediaDevices
    }
    CaptureSession {
        Component.onCompleted: {
            camera.start()
        }
        id:captureSession
        camera: Camera { id: camera }
        imageCapture: ImageCapture {
            onErrorOccurred: function(requestId, error, message) {
                console.log("Error occurred:"+message+"\nCamera active:"+camera.active+"\nImage capture ready:"+captureSession.imageCapture.readyForCapture+"\n")
            }
            onImageCaptured: {
                console.log("Image captured\n")
            }
        }
        videoOutput: videoOutput
    }
    VideoOutput {
        id: videoOutput
        anchors.fill: parent
    }
}

这是应用程序输出:

E Zygote  : isWhitelistProcess - Process is Whitelisted
E Zygote  : accessInfo : 1
I tQuickAppBackU: Late-enabling -Xcheck:jni
E tQuickAppBackU: Unknown bits set in runtime_flags: 0x8000
D ActivityThread: setConscryptValidator
D ActivityThread: setConscryptValidator - put
W System  : ClassLoader referenced unknown path:
D PhoneWindow: forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4274 com.android.internal.policy.DecorView.updateColorViews:1547 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3252 android.view.Window.setFlags:1153 com.android.internal.policy.PhoneWindow.generateLayout:2474
I MultiWindowDecorSupport: [INFO] isPopOver = false
I MultiWindowDecorSupport: updateCaptionType >> DecorView@85f9c98[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
D MultiWindowDecorSupport: setCaptionType = 0, DecorView = DecorView@85f9c98[]
D Qt JAVA : Class org.qtproject.qt.android.multimedia.QtAudioDeviceManager does not implement setActivity method
I QtCore  : Start
I Qt      : qt started
I ViewRootImpl@879196a[QtActivity]: setView = com.android.internal.policy.DecorView@85f9c98 TM=true MM=false
I ViewRootImpl@879196a[QtActivity]: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=11 res=0x7 s={true 513189830656} ch=true
D OpenGLRenderer: createReliableSurface : 0x777c754e40(0x777c7f6000)
D OpenGLRenderer: makeCurrent EglSurface : 0x0 -> 0x0
I mali_winsys: new_window_surface() [1080x2400] return: 0x3000
D OpenGLRenderer: eglCreateWindowSurface : 0x777c750900
D OpenGLRenderer: makeCurrent EglSurface : 0x0 -> 0x777c750900
W Gralloc3: mapper 3.x is not supported
I gralloc : Arm Module v1.0
I ViewRootImpl@879196a[QtActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D InputMethodManager: prepareNavigationBarInfo() DecorView@85f9c98[QtActivity]
D InputMethodManager: getNavigationBarColor() -855310
D InputMethodManager: prepareNavigationBarInfo() DecorView@85f9c98[QtActivity]
D InputMethodManager: getNavigationBarColor() -855310
V InputMethodManager: Starting input: tba=org.qtproject.example.FirstQtQuickAppBackUp ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D InputMethodManager: startInputInner - Id : 0
I InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
I ViewRootImpl@879196a[QtActivity]: MSG_RESIZED: frame=(0,0,1080,2400) ci=(0,93,0,126) vi=(0,93,0,126) or=1
D InputMethodManager: prepareNavigationBarInfo() DecorView@85f9c98[QtActivity]
D InputMethodManager: getNavigationBarColor() -855310
V InputMethodManager: Starting input: tba=org.qtproject.example.FirstQtQuickAppBackUp ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
D InputMethodManager: startInputInner - Id : 0
I SurfaceView: onWindowVisibilityChanged(0) true org.qtproject.qt.android.QtSurface{545da3c V.E...... ......I. 0,0-0,0 #1} of ViewRootImpl@879196a[QtActivity]
I ViewRootImpl@879196a[QtActivity]: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=8 res=0x1 s={true 513189830656} ch=false
I SurfaceView: surfaceCreated 1 #8 org.qtproject.qt.android.QtSurface{545da3c V.E...... ......ID 0,0-1080,2181 #1}
I SurfaceView: surfaceChanged (1080,2181) 1 #8 org.qtproject.qt.android.QtSurface{545da3c V.E...... ......ID 0,0-1080,2181 #1}
I mali_winsys: new_window_surface() [1080x2181] return: 0x3000
I OpenGLRenderer: doUpdatePositionAsync is called and callVoidMethod
D InputMethodManager: HSIFW - flag : 0
I InputMethodManager: hideSoftInputFromWindow ignore mServedView == null or mServedView.getWindowToken() != windowToken, mServedView :DecorView@85f9c98[QtActivity]
W System.err: java.lang.IllegalArgumentException: Invalid pixel_format=1598379073
W System.err:   at android.hardware.Camera$Parameters.setPreviewFormat(Camera.java:3182)
D SensorManager: registerListener :: 1, LSM6DSL Accelerometer, 200000, 0,
W System.err: java.lang.IllegalArgumentException: Invalid pixel_format=1598379073
W System.err:   at android.hardware.Camera$Parameters.setPreviewFormat(Camera.java:3182)
W Gralloc3: allocator 3.x is not supported
W OpenGLRenderer: [SurfaceTexture-0-9089-0] bindTextureImage: clearing GL error: 0x500
W OpenGLRenderer: [SurfaceTexture-0-9089-0] bindTextureImage: clearing GL error: 0x500

最后两行是递归的并重复几次。环境:

  • qt 6.2.2
  • 窗户 10
  • qtcreator 6.0.0
  • 手机架构:arm64-v8a

有人可以帮我解决这个问题吗?希望我说清楚了。先感谢您

4

0 回答 0