revision of example 'camera'

This commit is contained in:
pls.153 2022-11-09 15:59:03 +01:00
parent dd61e73fd1
commit eee2adf6a8
2 changed files with 14 additions and 14 deletions

View file

@ -7,6 +7,9 @@ Rectangle {
width: 640
height: 360
color: "black"
Screen.orientationUpdateMask:
Qt.LandscapeOrientation | Qt.PortraitOrientation |
Qt.InvertedLandscapeOrientation | Qt.InvertedPortraitOrientation
property int rotation: 0 // iOS: saved image will be rotated by this angle
@ -30,26 +33,24 @@ Rectangle {
anchors.fill: parent
anchors.bottomMargin: listView.height + 10
focus: visible // to receive focus and capture key events when visible
autoOrientation: (Qt.platform.os === "android")
autoOrientation: true
Component.onCompleted: adaptOrientation(Screen.orientation)
Component.onCompleted: updateImageRotation(Screen.orientation)
}
// for iOS
function adaptOrientation(orientation) {
function updateImageRotation(orientation) {
if (Qt.platform.os === "ios") {
var angle = 0
switch (orientation) {
case Qt.PortraitOrientation: angle = -90; break
case Qt.InvertedLandscapeOrientation: angle = 180; break
case Qt.InvertedPortraitOrientation: angle = 90; break
case Qt.LandscapeOrientation: rotation = 0; break
case Qt.PortraitOrientation: rotation = 90; break
case Qt.InvertedLandscapeOrientation: rotation = 180; break
case Qt.InvertedPortraitOrientation: rotation = -90; break
}
videoOutput.orientation = angle
rotation = (Math.abs(angle) === 90) ? -angle : angle
}
}
Screen.onOrientationChanged: adaptOrientation(Screen.orientation)
Screen.onOrientationChanged: updateImageRotation(Screen.orientation)
// menu buttons

View file

@ -40,10 +40,9 @@ Note
----
While testing on different devices (phone/tablet), I discovered that they may
behave differently regarding the orientation (both video output and saved
images) even if running the same OS. So, to adapt to your device's behavior,
you need to play around with `autoOrientation` and the angles in function
`adaptOrientation()`; see also Lisp function `qt:rotate-image`.
behave differently regarding the saved image orientation, even if running the
same OS. So, to adapt to your device's behavior, you need to play around with
`rotation` in `updateImageRotation()` (QML). See also `qt:rotate-image` (Lisp).
The current settings worked for me on both an android phone and an iPhone (both
older models).