Skip to content

Commit

Permalink
Merge pull request #32 from seanpcoyle/fix-degrees
Browse files Browse the repository at this point in the history
fix(android): orientation calculation
  • Loading branch information
mgcrea authored May 3, 2024
2 parents a229737 + a74ab2f commit 43a3f0c
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,32 @@ public Object callback(@NotNull Frame frame,
private InputImage getInputImageFromFrame(@NotNull Frame frame) {
try {
Image mediaImage = frame.getImage();
String orientation = frame.getOrientation().getUnionValue();

Orientation orientation = frame.getOrientation();
return InputImage.fromMediaImage(
mediaImage,
Orientation.Companion.fromUnionValue(orientation.getUnionValue())
.toSurfaceRotation());
int degrees = toDegrees(orientation);

return InputImage.fromMediaImage(mediaImage, degrees);
} catch (FrameInvalidError e) {
Log.e(TAG, "Received an invalid frame.");
return null;
}
}

private int toDegrees(String orientation) {
switch (orientation) {
case "portrait":
return 0;
case "landscape-left":
return 90;
case "portrait-upside-down":
return 180;
case "landscape-right":
return 270;
default:
return 0;
}
};

private synchronized BarcodeScanner
getBarcodeScannerClient(@Nullable Map<String, Object> params) {
int formatsBitmap = getFormatsBitmapFromParams(params);
Expand Down

0 comments on commit 43a3f0c

Please sign in to comment.