Using an Android devices native camera

I’m building an app which I eventually plan to deploy to both Android and iOS. Currently I need to set the screen to show what the camera sees at the screens native size. I’m able to resize the plane, and display the camera to the plane. However the camera image is getting stretched and distorted in a really weird way. Is there a way I can resize the plane to the screen size and not have the camera image get distorted? Here is the code I’m currently using, I’ve attached this script to my plane object.

public class CameraLoader : MonoBehaviour {

    // Use this for initialization
    void Start () {
        WebCamTexture camera = new WebCamTexture();
        Renderer renderer = GetComponent<Renderer>();

        // set the size of the plane
        var height = Camera.main.orthographicSize * 2;
        var width = height * (Screen.width / Screen.height);
        transform.localScale = new Vector3(width, height, 1);

        renderer.material.mainTexture = camera;
        camera.Play();
    }

    // Update is called once per frame
    void Update () {

    }
}

Or if there is an easier way to just display what the camera sees full screen, that would be awesome.

My first guess is that the reason why it gets distorted is becaurse the aspect of the device input is diffirent than the screen’s aspect ratio. We have done a plugin called Camera Capture Kit for both Android/iOS ( https://www.assetstore.unity3d.com/en/#!/content/56673 ) - we tried to tacle this issue by extending the camera preview texture so that it cuts some of the input in the sides ( on iOS ).

( You can also stretch the texture to fit the width of the screen and then scale the height according to the aspect of the iOS camera. This is what Apple does in their native camera app. Thats also why the UI is put on a black overlay in the bottom instead of the camera input filling the entire screen. )

Getting the aspect ratio of the device can be a bit tricky but we did it by capturing a frame from the camera and reading the width/height of the captured texture. WebCamTexture has a requested width/height as well , however the aspect is always 1,5 on iOS so you can start to experiment with that. ( it comes from the time iOS screens were 320x480 )

Cheers