Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by lvaliauga · May 06, 2020 at 10:03 AM · mobile deviceswebcamtexturewebcamaspect-ratioaspectratio

WebCam Texture scaling on iPhoneX

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

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));
     }
 }


all-three.jpg (42.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by b_mayank · Jun 27, 2020 at 10:01 AM

I'm also stuck at this point. @lvaliauga Did you figured it out how to do it? if yes, please can you show how did you do it. <3

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

128 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WebCameTexture.Play() Could not connect pins - RenderStream() 5 Answers

Take photo from webcam (not grab frame from video stream) 0 Answers

Problems with webcam 1 Answer

3d object inside the canvas panle not show in gameview 0 Answers

Webcamtexture at 1080p 50fps produces black image 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges