cordova-plugin-camera-preview: Height and Width being ignored in Take Picture
I defined the height and width in my application but the plugin is ignoring it and always outputing the same thing.
`CameraPreview.takePicture({width: 640, height: 640, quality: 85}, (base64Data)=>{
});`
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 17 (9 by maintainers)
Commits related to this issue
- Android: fix getOptimalPictureSize 'perfect match' works only on first iteration — committed to waitopiggu/cordova-plugin-camera-preview by waitopiggu 6 years ago
@waitopiggu @Choppe l I tried something similar on my clone, so the problem with that is that given that the aspect ratio of the visualization doesn’t match the aspect ratio of the capture then the captured image could look cropped, or have extra space.
So my solution was, start the camera in a preview area of 0x0 to get the supported camera sizes, then pick the size I’m interested in, then stop the camera again, and restart it in a region that respects the aspect ratio of my capture image.
This flow works perfectly every time, and now the preview and the capture match, and I can even do 16MP images (for this I need a patch that’s not part of the upstream, that requires to store the image into a file instead of base64 as base64 is just too damn expensive).
Right now I’m facing a memory leak, which happens after I take every picture stop the camera then restart it. I may need to add a method that gets the supported sizes for all the cameras without having the camera started, kind of a static method.
I am hitting the same issue in Android. On my device, getOptimalPictureSize() is always returning 720x1280, regardless of the specified width, height and screen orientation.
From what I can tell, since the size variable is overwritten inside the supported sizes loop, my desired width and height are never found.
Eg: Outside of the loop size is set at width = 640, height = 480. Starting the second loop iteration, width = 320, height = 240. Etc.
As @millecker says, the “perfect match” code won’t be hit unless the requested size matches the first supported size.