Reputation: 17
I'm new at qml. I'm working in windows 10, Qt creator 6.0.0, using Mingw64 as compiler and Qt 6.2.2. I'm trying to take a picture clicking on the screen.
import QtQuick
import QtCore
import QtMultimedia
Window {
id: main_window
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableHeight
visible: true
CaptureSession {
id:captureSession
videoOutput: videoOutput
Component.onCompleted: camera.start()
camera: Camera {
cameraDevice: MediaDevices.defaultVideoInput
}
imageCapture: ImageCapture {
onErrorOccurred: {
console.log("Error occurred\n")
}
onImageCaptured: {
console.log("Image captured\n")
}
onImageSaved: {
console.log("Image saved\n")
}
}
}
VideoOutput {
id:videoOutput;
anchors.fill: parent;
}
MouseArea {
anchors.fill: parent;
onClicked: captureSession.imageCapture.capture();
}
}
My main.cpp file is the default file of QtQuick application template.
I checked the default path for pictures and its file:///C:/Users/myname/Pictures
and never found the picture.
The only output I'm getting is Image captured
, so I guess the image is being saved. What colud the problem be? thank you in advance
Upvotes: 0
Views: 706
Reputation: 244291
The capture
method does not save any file, it only takes the image and saves it in a QImage that can be used to display in an Item Image through the preview property. If you want to save the image in a specific path then use captureToFile
, you also have other errors.
import QtCore
import QtQuick
import QtMultimedia
Window {
id: main_window
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableHeight
visible: true
MediaDevices {
id: mediaDevices
}
CaptureSession {
id: captureSession
videoOutput: videoOutput
Component.onCompleted: camera.start()
camera: Camera {
cameraDevice: mediaDevices.defaultVideoInput
}
imageCapture: ImageCapture {
onErrorOccurred: function(requestId, error, message) {
console.log("Error occurred", requestId, error, message);
}
onImageCaptured: function(requestId, previewImage) {
console.log("Image captured", requestId, previewImage);
}
onImageSaved: function(requestId, path) {
console.log("Image saved", requestId, path);
}
}
}
VideoOutput {
id: videoOutput
anchors.fill: parent
}
MouseArea {
anchors.fill: parent
onClicked: function() {
captureSession.imageCapture.captureToFile("C:/Users/myname/Pictures");
}
}
}
Upvotes: 1