Fix crop bounds exceeding image bounds due to EXIF rotation on Android
This commit is contained in:
@@ -249,15 +249,11 @@ export default function CameraScreen({
|
|||||||
// -- DOWNSCALE & CROP TO EXACTLY 3:2 --
|
// -- DOWNSCALE & CROP TO EXACTLY 3:2 --
|
||||||
try {
|
try {
|
||||||
console.log('Manipulating image to 3:2 ratio and downscaling to prevent OOM...');
|
console.log('Manipulating image to 3:2 ratio and downscaling to prevent OOM...');
|
||||||
let w = rawWidth;
|
// ALWAYS read true dimensions from ImageManipulator.
|
||||||
let h = rawHeight;
|
// expo-camera rawWidth/rawHeight ignores EXIF rotation, causing crop bounds to exceed image bounds!
|
||||||
|
const info = await ImageManipulator.manipulateAsync(capturedUri, []);
|
||||||
// If USB camera didn't provide width/height, read them
|
let w = info.width;
|
||||||
if (!w || !h) {
|
let h = info.height;
|
||||||
const info = await ImageManipulator.manipulateAsync(capturedUri, []);
|
|
||||||
w = info.width;
|
|
||||||
h = info.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
const actions: ImageManipulator.Action[] = [];
|
const actions: ImageManipulator.Action[] = [];
|
||||||
const isLandscape = w >= h;
|
const isLandscape = w >= h;
|
||||||
@@ -290,10 +286,10 @@ export default function CameraScreen({
|
|||||||
}
|
}
|
||||||
actions.push({
|
actions.push({
|
||||||
crop: {
|
crop: {
|
||||||
originX: Math.round(originX),
|
originX: Math.max(0, Math.floor(originX)),
|
||||||
originY: Math.round(originY),
|
originY: Math.max(0, Math.floor(originY)),
|
||||||
width: Math.round(cropWidth),
|
width: Math.min(w - Math.max(0, Math.floor(originX)), Math.floor(cropWidth)),
|
||||||
height: Math.round(cropHeight)
|
height: Math.min(h - Math.max(0, Math.floor(originY)), Math.floor(cropHeight))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -315,7 +311,7 @@ export default function CameraScreen({
|
|||||||
console.log('Successfully manipulated and cropped image');
|
console.log('Successfully manipulated and cropped image');
|
||||||
} catch (manipError) {
|
} catch (manipError) {
|
||||||
console.error('Failed to manipulate image, preventing OOM crash!', manipError);
|
console.error('Failed to manipulate image, preventing OOM crash!', manipError);
|
||||||
alert('Fehler bei der Bildverarbeitung! Das Bild ist zu groß oder das Format wird nicht unterstützt.');
|
alert('Bildverarbeitungs-Fehler: ' + (manipError.message || manipError.toString()));
|
||||||
onCancel();
|
onCancel();
|
||||||
return; // Abort here so we don't send a 16MB raw image to PreviewScreen
|
return; // Abort here so we don't send a 16MB raw image to PreviewScreen
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user