Nativescript-plugin-firebase: Camera is stretched when using width and height

Created on 21 May 2018  路  13Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

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.

Android ML Kit

Most helpful comment

I solved this!
I will create a PR soon

All 13 comments

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...
screenshot_20190115-202248
screenshot_20190115-202258

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:

https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/794467a9d72b66247c1343eee3a7665c6b00306c/src/mlkit/mlkit-cameraview.android.ts#L130

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thunder413 picture thunder413  路  3Comments

tsili852 picture tsili852  路  3Comments

dopefatimah picture dopefatimah  路  3Comments

tactusoft picture tactusoft  路  3Comments

EddyVerbruggen picture EddyVerbruggen  路  3Comments