2016-11-23 17 views
0

特定の解像度で画像をキャプチャしたい。 私はこのコードを使用しましたが、最後の解像度とキャプチャされた画像の解像度でカメラからキャプチャした画像は、サイズ(1280,720)に変更されません。私は画像をキャプチャする前に解像度を変更したい。qmlカメラの画像をキャプチャする前の解像度を変更する

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

最新の解像度は?イメージをキャプチャする前に解像度を変更するという意味ですか?適切なコードを記入してください。 – folibis

答えて

2

多くの場合、QMLカメラの動作は奇妙であり、いくつかの依存性は十分に文書化されていません。

とにかく、コードは以下のことは私のために動作します:あなたが成功した解像度を切り替えたい場合は、あなたがstop()start()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 
      } 
     } 
    } 
} 

あなたはonImageCapturedに戻っ(160,120)に解像度を切り替えるしようとした場合には、フリーズしたので、私はQueuedConnectionのいくつかの種類を取得するためにTimerを使用。

関連する問題