using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TakePicture : MonoBehaviour
{
private int width;
private int height;
private int x;
private int y;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
StartCoroutine(ScreenShot_ReadPixels());
}
}
IEnumerator ScreenShot_ReadPixels()
{
Texture2D t = new Texture2D(width, height);
yield return new WaitForEndOfFrame();
t.ReadPixels(new Rect(x, y, t.width, t.height), 0, 0);
t.Apply();
string path = Application.dataPath + "/1.png";
System.IO.File.WriteAllBytes(path, t.EncodeToPNG());
}
void FullScreen()
{
ScreenCapture.CaptureScreenshot(Application.dataPath + "/全屏.jpg");
}
}
|