关键代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class ScreenShot : MonoBehaviour {
public Camera ARCamera;
// Use this for initialization
void Start () {
ARCamera = GameObject.Find("ARCamera").GetComponent<Camera>();
}
// Update is called once per frame
void Update () {
}
//单机截屏
public void OnScreenShotClick() {
//获取当前时间
System.DateTime now = System.DateTime.Now;
string nowTime = now.ToString();
nowTime = nowTime.Trim();
nowTime = nowTime.Replace("/","-");
//创建并获取 截图的图片名称
string fileName = "ARScreenShot" + nowTime + ".png";
//如果运行的设备是Android 就截图
if (Application.platform == RuntimePlatform.Android)
{
//包含UI的截图
创建2D图片
参数一 图片宽度
参数二 图片高度
参数三 图片格式
参数四 是否映射
//Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
读取图片
参数一 要读取的视图的矩形区域。从当前渲染目标读取像素。
参数二 从哪里开始读取
参数三 从哪里结束
//texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
调用Apply截屏 成功
//textu