2016-11-23 32 views
0

我想用特定分辨率捕捉图像。 我使用了这段代码,但从最后一个分辨率的相机捕获的图像和捕获的图像的分辨率不会更改为大小(1280,720)。我想在捕捉图像之前更改分辨率。qml更改相机图像捕获前的分辨率

imageCapture { 
resolution: Qt.size(1280, 720) 
onImageCaptured: { 
photoPreview.source = preview 
} 
+0

最后的分辨率是多少?这是否意味着在捕获图像之前更改分辨率?请张贴适当的代码。 – folibis

回答

2

在很多情况下,QML Camera的行为很奇怪,有些依赖关系还没有很好的文档记录。

不管怎样,下面的代码对我的作品:

import QtQuick 2.6 
import QtQuick.Window 2.2 
import QtQuick.Layouts 1.3 
import QtQuick.Controls 1.4 
import QtMultimedia 5.6 

Window { 
    visible: true 

    width: 1280 
    height: 960 

    GridLayout { 
     id: grid 
     rows: 2 
     columns: 2 

     Item { 
      Layout.row: 0 
      Layout.column: 0 
      Layout.minimumWidth: 80 
      Layout.minimumHeight: 30 

      Button { 
       id: button 
       text: "capture" 
       onClicked: { 
        camera.stop(); 
        camera.viewfinder.resolution = "640x480"; 
        camera.start(); 
       } 
      } 
     } 

     Camera { 
      id: camera 
      captureMode: Camera.CaptureViewfinder 

      viewfinder.resolution: "160x120" 

      imageCapture { 
       id: cameracapture 

       onImageCaptured: { 
        photoPreview.source = preview // Show the preview in an Image 
        console.log("capture size: ", photoPreview.sourceSize); 
        timerHelper.restart(); 
       } 

      } 

      onCameraStateChanged: { 
       console.log("camera state changed to: ", cameraState); 
       if (cameraState == Camera.ActiveState && viewfinder.resolution == Qt.size(640,480)) { 
        cameracapture.capture(); 
       } 
      } 

      function cameraHelper() { 
       console.log("Stopping cam..."); 
       camera.stop(); 
       viewfinder.resolution = "160x120"; 
       camera.start(); 
      } 
     } 

     Timer { 
      id: timerHelper 
      interval: 1 
      onTriggered: camera.cameraHelper(); 
     } 

     Item { 
      width: 640 
      height: 480 

      Layout.row: 1 
      Layout.column: 0 
      Layout.minimumWidth: 640 
      Layout.minimumHeight: 480 

      Image { 

       width: 640 
       height: 480 

       id: photoPreview 
      } 
     } 

     Item { 
      width: 640 
      height: 480 

      Layout.row: 1 
      Layout.column: 1 
      Layout.minimumWidth: 640 
      Layout.minimumHeight: 480 

      VideoOutput { 
       source: camera 
       anchors.fill: parent 
       focus : visible // to receive focus and capture key events when visible 
      } 
     } 
    } 
} 

如果你想成功切换分辨率,你必须stop()start()Camera

冻结,如果你尝试切换分辨率回(160,120)onImageCaptured,所以我用一个Timer获得某种QueuedConnection