Unity内截屏实现

本文介绍了Unity中三种截屏方法:Application.CaptureScreenshot(已废弃)、Texture2D.ReadPixels和RenderTextures。Texture2D.ReadPixels允许定制截图大小,而RenderTextures能指定摄像机截图,适合需要屏蔽UI的情况。CaptureScreenshot适用于快速全屏截图,但官方不再推荐。
摘要由CSDN通过智能技术生成

Unity内一般有三种截屏的方法:

  1. Application.CaptureScreenshot
  2. Texture2D.ReadPixels
  3. RenderTextures

图片保存地址一般设为: Application.persistentDataPath + “/screen1.png”

参考persistentDataPath的文档说明:The value is a directory path where data expected to be kept between runs can be stored. When publishing on iOS and Android, persistentDataPath will point to a public directory on the device.


下面我们来看具体的实现:

Application.CaptureScreenshot

文档上已将此方法标记为 Obsolete 。
https://docs.unity3d.com/ScriptReference/Application.CaptureScreenshot.html

优点:简单,可以快速地截取某一帧的画面、全屏截图

缺点:
1. 不能针对摄像机截图
2. 定制大小截图不方便

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnMouseDown() {
        Application.CaptureScreenshot(Application.persistentDataPath + "/CaptureScreenshot.png");
    }
}
Texture2D.ReadPixels

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值