unity3d中截屏转化为sprite
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Demo : MonoBehaviour {
public void captureToImg(){
var cptrAddr = "test.png";
var readAddr = Application.persistentDataPath + "/" + cptrAddr;
Application.CaptureScreenshot (cptrAddr);
StartCoroutine (getTexture2d ("file://" + readAddr));
}
IEnumerator getTexture2d(string url){
WWW www = new WWW (url);
yield return www;
if (www.isDone && www.error == null) {
//GameObject.Find("Cube01").GetComponent<Renderer>().material.mainTexture = www.texture;
GameObject.Find("Image01").GetComponent<Image>().sprite = Sprite.Create(www.texture,new Rect(0,0,Screen.width,Screen.height),new Vector2(0.5f,0.5f));
}
}
}