Skip to content

Commit 6e236a5

Browse files
committed
example: update the checking of rotation
1 parent e0ba0f1 commit 6e236a5

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

example/src/components/Scanner.tsx

+18-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default function Scanner(props:ScannerProps) {
3131
const [viewBox,setViewBox] = useState("0 0 1080 1920");
3232
const [pointsText, setPointsText] = useState("default");
3333
const takenShared = useSharedValue(false);
34-
const [taken,setTaken] = useState(false);
3534
const photo = useRef<PhotoFile|null>(null);
3635
const previousResults = useRef([] as DetectedQuadResult[]);
3736
const device = useCameraDevice("back");
@@ -50,13 +49,24 @@ export default function Scanner(props:ScannerProps) {
5049

5150
const getFrameSize = () => {
5251
let width, height;
53-
if (frameWidth>frameHeight && Dimensions.get('window').width>Dimensions.get('window').height){
54-
width = frameWidth;
55-
height = frameHeight;
56-
}else {
57-
console.log("Has rotation");
58-
width = frameHeight;
59-
height = frameWidth;
52+
if (frameWidth.value>frameHeight.value){
53+
if (Dimensions.get('window').width>Dimensions.get('window').height) {
54+
width = frameWidth.value;
55+
height = frameHeight.value;
56+
}else{
57+
console.log("Has rotation");
58+
width = frameHeight.value;
59+
height = frameWidth.value;
60+
}
61+
}else if (frameWidth.value<frameHeight.value) {
62+
if (Dimensions.get('window').width<Dimensions.get('window').height) {
63+
width = frameWidth.value;
64+
height = frameHeight.value;
65+
}else{
66+
console.log("Has rotation");
67+
width = frameHeight.value;
68+
height = frameWidth.value;
69+
}
6070
}
6171
return [width, height];
6272
}
@@ -96,7 +106,6 @@ export default function Scanner(props:ScannerProps) {
96106
console.log("take photo");
97107
if (camera.current) {
98108
console.log("using camera");
99-
setTaken(true);
100109
takenShared.value = true;
101110
await sleep(500);
102111
photo.current = await camera.current.takePhoto();
@@ -115,7 +124,6 @@ export default function Scanner(props:ScannerProps) {
115124
}
116125
}else{
117126
Alert.alert("","Failed to take a photo");
118-
setTaken(false);
119127
takenShared.value = false;
120128
}
121129
}

ios/DetectionFrameProcessorPlugin.swift

+2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ public class DetectionFrameProcessorPlugin: FrameProcessorPlugin {
4343
}else if UIDevice.current.orientation == UIDeviceOrientation.landscapeRight {
4444
degree = 270.0;
4545
}
46+
4647
if degree != 0.0 {
4748
image = DetectionFrameProcessorPlugin.rotate(image:image,degree:degree)
4849
}
50+
4951
let capturedResult = VisionCameraDynamsoftDocumentNormalizer.cvr.captureFromImage(image, templateName: templateName)
5052
let results = capturedResult.items
5153
if results != nil {

0 commit comments

Comments
 (0)