Quantcast
Channel: Questions in topic: "webcam"
Viewing all articles
Browse latest Browse all 256

WebCam Texture scaling on iPhoneX

$
0
0
Hi, I am trying to make a fullscreen camera feed image on a mobile phone (iPhone X). - - A: If I set AspectRatio Fitter to 'Fit in Parent' then it appears at full size but scaled down. - B: If I set the image (on which I am applying the WebCam Texture) AspectRatio Fitter to 'Envelope Parent' (which is Canvas) then the image appears really cropped up. - C: I tried using **SetTextureScale("_MainTex", new Vector2(1f, 1f));** but it doesn't seem to affect the image being way out of screen size. If I set the texture scaling to 1.5f it seems I get the correct image size but scales the texture, not the image... (looks cool btw :D) - Please help me understand how the image scaling works in terms of aspect ratio. How can I have a full-screen webcam image, but also at the normal scale? - ![alt text][1] This is a code I am using: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class WebCam : MonoBehaviour { private bool camAvailable; private WebCamTexture backCam; private Texture defaultBackground; public RawImage backgroud; public AspectRatioFitter fit; void Start() { defaultBackground = backgroud.texture; WebCamDevice[] devices = WebCamTexture.devices; if (devices.Length == 0) { Debug.Log("No Cameras found"); camAvailable = false; return; } for (int i = 0; i < devices.Length; i++) { if (!devices[i].isFrontFacing) { backCam = new WebCamTexture(devices[i].name, Screen.width, Screen.height); } } if (backCam == null) { Debug.Log("Back Camera failed..."); return; } backCam = new WebCamTexture(devices[0].name, Screen.width, Screen.height); backCam.Play(); backgroud.texture = backCam; camAvailable = true; }//EO START void Update() { if (!camAvailable) { return; } float ratio = (float)backCam.width / (float)backCam.height; fit.aspectRatio = ratio; float scaleY = backCam.videoVerticallyMirrored ? -1f : 1f; backgroud.rectTransform.localScale = new Vector3(1f, scaleY,1f); int orient = -backCam.videoRotationAngle; backgroud.rectTransform.localEulerAngles = new Vector3(0,0,orient); backgroud.material.SetTextureScale("_MainTex", new Vector2(1f, 1f)); } } [1]: /storage/temp/158687-all-three.jpg

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>