I have a barcode scanner with width 400 and height 200, and the camera view is stretch to make everything really flat, looks like it's scaling the full screen camera down to the dimensions without keeping aspect ratio.
Yeah, I noticed this as well (only on Android actually).
I have this issue on iOS as well. Can you fix this? Or is this a Firebase MLKit issue?
Can you share the UI code?
The code in the example
Changing the width and height to 100% does not distort the image
So that means it's ok now?
Yea, but it would be nice to be able to have a camera view that's not the full size
height and width also stretch image, it seems there is bad computing behind display aspect ratio. There is circular tag on screens...


Android, Huawei P10 Pro
I hope this is fix:
In file mlkit-cameraview.android.js, line 243 replace with this:
var pict = sizePair.pictureSize;
var diff = Math.abs((size.width / size.height) - (pict.width / pict.height));
it compute preview/picture pair with the closest aspect ratio.
To the extent that this is an Android-specific issue, I think the following line is responsible:
The selectSizePair function seems to be looking for the previewSize which most closely matches the aspect ratio of the preview display area -- however, it assumes that the preview display area is always 1400x1200. Identifying the camera preview's current height & width, and updating it based on screen orientation or other layout changes does not currently appear implemented.
Yeah that TODO is waiting to be solved indeed. Happy to merge a PR if someone would like to take a stab at it :)
I solved this!
I will create a PR soon
@MurilloBrand That would be great!
Most helpful comment
I solved this!
I will create a PR soon