Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Working in QML with camera

    QML and Qt Quick
    2
    7
    505
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mikeeeeee last edited by Mikeeeeee

      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. qml

      import 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")
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • M
        Mikeeeeee last edited by

        This too not work:

        photoImage.source = photoPreview.source
        

        Here I found a simple application .Help please on the basis of it to do function photography.

        1 Reply Last reply Reply Quote 0
        • M
          Mikeeeeee last edited by

          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)
              }
          
          1 Reply Last reply Reply Quote 0
          • M
            Mikeeeeee last edited by

            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
                }
            
            J.Hilk 1 Reply Last reply Reply Quote 0
            • J.Hilk
              J.Hilk Moderators @Mikeeeeee last edited by

              @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.

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

              Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply Reply Quote 1
              • M
                Mikeeeeee last edited by

                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 this

                photoImage.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?

                1 Reply Last reply Reply Quote 0
                • M
                  Mikeeeeee last edited by

                  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;
                  }
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post