Merge pull request #1468 from waitopiggu/master

fix(Android): image stretched instead of cropped
This commit is contained in:
Sibelius Seraphini 2018-04-14 16:58:36 -03:00 committed by GitHub
commit dba607bff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -161,15 +161,26 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
float width = right - left;
float height = bottom - top;
float ratio = getAspectRatio().toFloat();
int orientation = getResources().getConfiguration().orientation;
int correctHeight;
int correctWidth;
this.setBackgroundColor(Color.BLACK);
if (height / width > ratio) {
if (orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) {
if (ratio * height < width) {
correctHeight = (int) (width / ratio);
correctWidth = (int) width;
} else {
correctWidth = (int) (height * ratio);
correctHeight = (int) height;
}
} else {
if (ratio * width > height) {
correctHeight = (int) (width * ratio);
correctWidth = (int) width;
} else {
correctWidth = (int) (height / ratio);
correctHeight = (int) height;
correctWidth = (int) (height * ratio);
}
}
int paddingX = (int) ((width - correctWidth) / 2);
int paddingY = (int) ((height - correctHeight) / 2);