ArcGIS for Developers

CameraDialog QML Type

(BETA) Allows use of native device camera apps. More...

Import Statement: import ArcGIS.AppFramework.Multimedia 1.0

Properties

Signals

Methods

Detailed Description

The CameraDialog component provides access to the system's capera to take photos and movies, using the best resolution supported by the system. For iOS and Android, it will open the device's native camera app. For other platforms (macOS, Windows and Linux) this component will instead open a custom camera app. After the capture is complete, you can play back recorded video or view captured photos before saving the file on your device.

To use this component, the camera, microphone, audio, and external storage capabilities all need to be enabled in the Capabilities tab of the Settings tool.

The following code sample demonstrates the usage of CameraDialog providing an interface to capture either a camera or video and save it to the device.

Item {
    property string documents: AppFramework.standardPaths.writableLocation(StandardPaths.DocumentsLocation)


    ColumnLayout {
        anchors.fill: parent

        Row {

            Switch {
                id: cameraModeSw
                text: "Image/Video"

                onClicked: {
                    updateTxt();
                }
            }

            Switch {
                id: cameraFlagSw
                text: "Save to Camera Roll"

                onClicked: {
                    updateTxt();
                }
            }
        }

        Row {

            Switch {
                id: captureToFolderSw
                text: "File/Folder"

                onClicked: {
                    updateTxt();
                }
            }

            Button {
                text: "Capture to location"

                onClicked: {
                    if (captureToFolderSw.checked) {
                        documentDialog.selectFolder = true;
                    } else {
                        documentDialog.selectFolder = false;
                    }
                    documentDialog.open();
                }
            }
        }

        Row {
            Button {
                text: "Open Camera Dialog"

                onClicked: {
                    console.log(cameraDialog.captureToLocation);

                    cameraDialog.open();
                    updateTxt();
                }
            }
        }

        TextArea {
            id: propTxt
            Layout.fillWidth: true
            wrapMode: Text.WrapAnywhere
        }
    }

    CameraDialog {
        id: cameraDialog

        captureMode: cameraModeSw.checked? CameraDialog.CameraCaptureModeVideo : CameraDialog.CameraCaptureModeStillImage
        captureFlags: cameraFlagSw.checked? CameraDialog.CameraCaptureFlagCameraRoll : CameraDialog.CameraCaptureFlagNone
        //captureToLocation: AppFramework.userHomeFolder.folder("Test123").fileUrl("newimage.jpg")
        title: "CameraDialog Test"

        onCaptureToLocationChanged: {
            console.log("captureToLocation: " + captureToLocation);
        }

        onAccepted: {
            console.log("Accepted");
            updateTxt();
        }

        onRejected: {
            console.log("Rejected");
            updateTxt();
        }

        onErrorChanged: {
            console.log("Error: " + error.errorMessage);
        }
    }

    DocumentDialog {

        id: documentDialog

        selectExisting: false
        selectMultiple: false

        onAccepted: {
            cameraDialog.captureToLocation = fileUrl;
            updateTxt();
        }

    }

    function updateTxt() {
        propTxt.text = "Camera Dialog Properties:-\n" +
                "cameraInfo: " + cameraDialog.cameraInfo + "\n" +
                "captureFlags: " + cameraDialog.captureFlags + "\n" +
                "captureMode: " + cameraDialog.captureMode + "\n" +
                "captureToLocation: " + cameraDialog.captureToLocation + "\n" +
                "error message: " + cameraDialog.error.errorMessage + "\n" +
                "error code: " + cameraDialog.error.errorCode + "\n" +
                "fileUrl: " + cameraDialog.fileUrl + "\n" +
                "title: " + cameraDialog.title + "\n" +
                "visible: " + cameraDialog.visible + "\n"
    }

    Component.onCompleted: {
        updateTxt();
    }
}

Enumerations

CameraCaptureFlag enumeration

NameValue
CameraDialog.CameraCaptureFlagNone0
CameraDialog.CameraCaptureFlagCameraRoll1

CameraCaptureMode enumeration

Enum describing the potential capture modes for the camera. Informs the captureMode property.

NameValue
CameraDialog.CameraCaptureModeStillImage0
CameraDialog.CameraCaptureModeVideo1

Property Documentation

cameraInfo : object

This property by default returns the state of the camera, such as flash. If this property is set, the camera object will honor if the platform supports it and it is retained throughout the app. If this property is set to null, then it will return to the default values.


captureFlags : int

Supply a flag such as CameraRoll, in order to add the captured media to the camera roll asset.


captureMode : int

Controls whether the camera will capture video or still images. Informed by the CameraCaptureMode enum.


captureToLocation : url

If a valid file URL is supplied for image or video on appropriate mode, the captured media will save to this location. Make sure the path is a valid file URL before supplying the location.

On Android, you can only provide the app sandbox location.


error : object

A CameraDialogError object that provides details of the last error encountered, such as errorCode and errorMessage.


fileUrl : url

The URL of file of the previously captured image or video. This is usually set after the onAccepted signal is emitted.


title : string

If set, the supported platforms will display this title when the camera dialog opens.


Signal Documentation

accepted()

Signal emitted when the camera dialog has been accepted, and the video or photo saved to the device.


rejected()

Signal emitted when the camera dialog has either been rejected or the camera cannot be opened. Informed by the CameraError enum.


Method Documentation

object close()


object open()

On iOS and Android, opens the device's default camera app to capture an image or video. On Windows, macOS and Linux, opens a custom camera control to capture an image or video.

Be aware that currently, it is not possible to record a video on Windows using this component.