Working in QML with camera
-
Hi!
I can display the picture from the camera on the screen. But the picture does not rotate when you turn the phone. Please tell me how to turn it with the phone. Also trying to take a photo when I click on a single button and display this photo in the picture, but can't do it. Help please. Below is my code. qmlimport QtQuick 2.12 import QtMultimedia 5.12 Camera1Form { buttonPhoto.onClicked: //photo { photoImage.source= camera } }
ui.qml
import QtQuick 2.12 import QtQuick.Controls 2.12 import QtMultimedia 5.12 Item { width: 400 height: 700 property alias buttonPhoto: buttonPhoto property alias photoImage: photoImage property alias photoPreview: photoPreview property alias camera: camera Camera { id: camera imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash exposure { exposureCompensation: -1.0 exposureMode: Camera.ExposurePortrait } flash.mode: Camera.FlashRedEyeReduction imageCapture { onImageCaptured: { photoPreview.source = preview // Show the preview in an Image } } } VideoOutput { anchors.bottomMargin: 300 source: camera anchors.fill: parent focus : visible // to receive focus and capture key events when visible } Image { id: photoPreview } Image { id: photoImage x: 21 y: 433 width: 219 height: 215 fillMode: Image.PreserveAspectFit source: "qrc:/qtquickplugin/images/template_image.png" } Button { id: buttonPhoto x: 264 y: 507 text: qsTr("Photo") } }
-
So I can save the picture. It remains to learn how to save it in the folder with the program, how to mirror the picture and how to rotate the camera with the tilt of the phone. Maybe you know how can something this be done?
buttonPhoto.onClicked: //photo { camera.imageCapture.captureToLocation("C:/Users/New Owner/Pictures/IMG_00000001.jpg") var imageFile =camera.imageCapture.capturedImagePath console.log("test: " + imageFile) }
-
So the camera shows correctly when turning the phone. It remains to learn how to save images in a folder with the program and how to upload them to the pictures.
VideoOutput { //anchors.bottomMargin: 300 source: camera anchors.fill: parent focus : visible // to receive focus and capture key events when visible autoOrientation: true }
-
So the camera shows correctly when turning the phone. It remains to learn how to save images in a folder with the program and how to upload them to the pictures.
VideoOutput { //anchors.bottomMargin: 300 source: camera anchors.fill: parent focus : visible // to receive focus and capture key events when visible autoOrientation: true }
@Mikeeeeee
have you taken a look at the camera example?https://doc.qt.io/qt-5/qtmultimedia-multimedia-declarative-camera-example.html
It has a capture feature.
-
I watched, but it is hard to understand this example. There are no comments in the code. And there is no ui.qml, so it is difficult to understand what is responsible for.
Connected a layer of C++ and then was able to save wherever I want.
But when I do thisphotoImage.source = "file:C:/Users/New Owner/Pictures/IMG_00000001.jpg"*
The photo changes only once, the next time you take a photo in this file, the picture still does not change. Apparently the cache is stored at an old picture. How to upload a new image from an old file?
-
QByteArray allows normally send image
QString AppCore::getImage(QString addressFile) { QImage myImage(addressFile); QByteArray bArray; QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); myImage.save(&buffer, "JPEG"); QString image("data:image/jpg;base64,"); image.append(QString::fromLatin1(bArray.toBase64().data())); return image; }