- using System;
- using UnityEngine;
- using System.IO;
- public class CropPicture : MonoBehaviour
- {
- publicCamera cropCamera;//待截图的目标摄像机
- RenderTexture renderTexture;
- Texture2D texture2D;
- void Start()
- {
- renderTexture =newRenderTexture(800,600,32);
- texture2D =newTexture2D(800,600, TextureFormat.ARGB32,false);
- cropCamera.targetTexture = renderTexture;
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- RenderTexture.active = renderTexture;
- texture2D.ReadPixels(newRect(0,0, renderTexture.width, renderTexture.height),0,0);
- texture2D.Apply();
- RenderTexture.active =null;
- byte[] bytes = texture2D.EncodeToPNG();
- File.WriteAllBytes(Application.dataPath +"//pic//"+ (DateTime.UtcNow -newDateTime(1970,1,1,0,0,0,0)).TotalMilliseconds +".png", bytes);
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2115340.html