从iPhone相机渲染的模糊图像

时间:2018-05-25 04:08:00

标签: c# ios unity3d textures screen-resolution

我正在Unity为iPhone开发一款基于照片的游戏,我在访问设备相机时遇到了分辨率问题。渲染到纹理的实时图像明显地像素化,并且拍摄并保存到照片库时的照片类似地像素化。看起来渲染到纹理的图像的分辨率低于相机/屏幕的原始分辨率,但我不确定为什么会这样。我该如何解决这个问题?谢谢!

using UnityEngine;
using UnityEngine.UI;

public class PhoneCamera : MonoBehaviour
{
    private bool camAvailable;
    private Texture defaultBackground;

    public static WebCamTexture backCam { get; set; }

    public RawImage background;
    public AspectRatioFitter fit;

    private void Start ()
    {
        defaultBackground = background.texture;
        WebCamDevice [] devices = WebCamTexture.devices;

        if (devices.Length == 0) {
            Debug.Log ("No camera detected");
            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 ("Unable to find back camera");
            return;
        }

        backCam.Play ();
        background.texture = backCam;

        camAvailable = true;
    }

    private void Update ()
    {
        if (!camAvailable)
            return;

        float ratio = (float)backCam.width / (float)backCam.height;
        fit.aspectRatio = ratio;

        float scaleY = backCam.videoVerticallyMirrored ? -1f : 1f;
        background.rectTransform.localScale = new Vector3 (1f, scaleY, 1f);

        int orient = -backCam.videoRotationAngle;
        background.rectTransform.localEulerAngles = new Vector3 (0, 0, orient);
    }
}

0 个答案:

没有答案