Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Working in QML with camera
QtWS25 Last Chance

Working in QML with camera

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 1.2k Views
  • 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 Offline
    M Offline
    Mikeeeeee
    wrote on last edited by Mikeeeeee
    #1

    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
    0
    • M Offline
      M Offline
      Mikeeeeee
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          Mikeeeeee
          wrote on last edited by
          #4

          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.HilkJ 1 Reply Last reply
          0
          • M Mikeeeeee

            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.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @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


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

            1 Reply Last reply
            1
            • M Offline
              M Offline
              Mikeeeeee
              wrote on last edited by
              #6

              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
              0
              • M Offline
                M Offline
                Mikeeeeee
                wrote on last edited by
                #7

                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
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved