ARFoundation系列讲解-24拍照并且保存到系统相册

一、Unity的截屏方式

1.使用 CaptureScreenshot Api ,这种方法只能截取全屏,一般很少使用这种方法。

 Application.CaptureScreenshot("Screenshot.png", 0);  

2.可以自定义截取的范围,但是有个缺点就是无法截取指定层级的画面。(比如我只想拍照,不需要截取拍照按钮和UI画面的话,就需要先隐藏掉UI界面后再截屏)。这种方法太麻烦了,也是很少使用。

    private Texture2D texture2D=null;
    private Rect rect = new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 1f, Screen.height * 1f);
    private IEnumerator ScreenshotAsyn()
    {
        if (texture2D != null) Destroy(texture2D);
        texture2D = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);

        texture2D.ReadPixels(rect, 0, 0);
        texture2D.Apply();
    }

3.截取指定相机层级画面。(这种方法比较常使用)

using UnityEngine;

/// <summary>截屏功能</summary>
public class Screenshot
{
    private s

猜你喜欢

转载自blog.csdn.net/a451319296/article/details/109339490