How to focus with QML Camera
on Android? I've tried all focusMode
but nothing works. Camera apps correctly focus on my device.
Here my QML file:
import QtQuick 2.3
import QtMultimedia 5.2
Item {
property int scanerButtonWidth: 80
property int scanerButtonHeight: 60
Rectangle {
width: parent.width
height: scanerButtonHeight + 10
color: Qt.rgba(0,0,0,1)
}
VideoOutput {
width: parent.width
height: parent.height
source: camera
anchors.fill: parent
autoOrientation: true
}
Camera {
id: camera
imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
captureMode: Camera.CaptureStillImage
exposure {
exposureMode: Camera.ExposureAuto
}
focus {
focusMode: Camera.FocusContinuous
focusPointMode: Camera.FocusPointCenter
}
imageCapture {
onImageCaptured: {
otpGeneratorApp.scanedQR_Code( preview, false, type )
qrCodeScanner.visible = false
}
}
}
Rectangle {
width: parent.width
height: scanerButtonHeight + 10
y: parent.height - ( height )
color: Qt.rgba(0,0,0,1)
Button {
id: captureButton;
width: scanerButtonWidth;
height: scanerButtonHeight;
x: parent.width * 0.5 - ( width / 2);
y: parent.height - ( height + 5);
text: qsTr( "[O]" );
onClicked: {
camera.imageCapture.capture();
}
}
Button {
id: focus
width: scanerButtonWidth;
height: scanerButtonHeight;
text: qsTr("Focus");
x: captureButton.x + ( captureButton.width + 10 );
y: parent.height - ( height + 5);
onClicked: {
camera.searchAndLock();
}
}
}
}
If you are using Qt 5.4 or below, you cannot. There is a bug in QCamera
that prevents the autofocus to be triggered. See the bug and a way to solve it here.
A solution has been merged and the bug is solved since Qt 5.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With