Crops Preview on Android
This commit is contained in:
parent
6cc3d89bec
commit
0e3e84e35b
|
@ -164,10 +164,22 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
|
||||||
if (null == preview) {
|
if (null == preview) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
float width = right - left;
|
||||||
|
float height = bottom - top;
|
||||||
|
float ratio = getAspectRatio().toFloat();
|
||||||
|
int correctHeight;
|
||||||
|
int correctWidth;
|
||||||
this.setBackgroundColor(Color.BLACK);
|
this.setBackgroundColor(Color.BLACK);
|
||||||
int width = right - left;
|
if (height / width > ratio) {
|
||||||
int height = bottom - top;
|
correctHeight = (int) (width * ratio);
|
||||||
preview.layout(0, 0, width, height);
|
correctWidth = (int) width;
|
||||||
|
} else {
|
||||||
|
correctHeight = (int) height;
|
||||||
|
correctWidth = (int)(height*ratio);
|
||||||
|
}
|
||||||
|
int paddingX = (int) ((width - correctWidth) / 2);
|
||||||
|
int paddingY = (int) ((height - correctHeight) / 2);
|
||||||
|
preview.layout(paddingX, paddingY, correctWidth+paddingX, correctHeight+paddingY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue