teslamotors / react-native-camera-kit

A high performance, easy to use, rock solid camera library for React Native apps.
MIT License
2.42k stars 577 forks source link

No image dimensions provided from capture #641

Open alexstanbury opened 4 months ago

alexstanbury commented 4 months ago

Describe the bug When capturing an image, I would expect there to be a height and width value returned, yet I only get the following:

{"name": "8AEEEE42-E902-4B6D-B00D-FBF68AF0A15D-1696-000003A7ECB1B040.jpg", "size": 1943477, "uri": "file:///private/var/mobile/Containers/Data/Application/6D9CE0E0-B496-41AF-8EF0-F4C7506AC7BF/tmp/8AEEEE42-E902-4B6D-B00D-FBF68AF0A15D-1696-000003A7ECB1B040.jpg"}

To Reproduce Steps to reproduce the behavior:

  1. Create Camera
  2. call capture
  3. Notice no width or height passed back.

Expected behavior There should be width and height passed back, it's a fundamental part of a camera library, surely?

Smartphone (please complete the following information):

zenovak commented 4 months ago

Took a dive on the native code on the android side, since it might be related to your usecase.

From the android native code: https://github.com/teslamotors/react-native-camera-kit/blob/master/android/src/main/java/com/rncamerakit/CKCamera.kt

...
        // ImageCapture
        imageCapture = ImageCapture.Builder()
            .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
            // We request aspect ratio but no resolution to match preview config, but letting
            // CameraX optimize for whatever specific resolution best fits our use cases
            .setTargetAspectRatio(screenAspectRatio)
            // Set initial target rotation, we will have to call this again if rotation changes
            // during the lifecycle of this use case
            .setTargetRotation(rotation)
            .build()

Seems like a lack of support for this feature than a bug. The resolutions are automatically decided by native libraries, and there isnt any public methods that return the resolution (least I couldnt find any)

You might have to do a workaround and get the resolutions from the captured temporary jpeg instead

DavidBertet commented 4 months ago

You right @alexstanbury. height/width are implemented on Android, not yet on iOS.

https://github.com/teslamotors/react-native-camera-kit/blob/master/src/types.ts

export type CaptureData = {
  uri: string;
  name: string;
  // Android only
  id?: string;
  path?: string;
  height?: number;
  width?: number;
  // iOS only
  size?: number;
};
DavidBertet commented 4 months ago

I pushed a PR to get that added 👍