Unity保存游戏效果图片,并显示出来
方案1:截屏保存,再显示。
核心知识:
1,Application.CaptureScreenshot("wuk.png");Unity会自动截屏保存在 Application.persistentDataPath+"/"+"wuk.png";
2,WWW 网页;
3,获取权限;
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
例1:
public Material image;
void Awake(){
Application.CaptureScreenshot("wuk.png");
}
void Start () {
StartCoroutine(getCapture());
}
IEnumerator getCapture(){
path=Application.persistentDataPath;
Debug.Log("path"+path);
www=new WWW("file://"+path+"/wuk.png");
yieldreturn www;
image.mainTexture=www.texture;
}
方案2:保存指定屏幕区域为png,并显示;
核心知识:
Texture2D.ReadPixels;System.IO.File.WriteAllBytes;
关键方法:
Texture2D.ReadPixels; Texture2D.Apply();Texture2D.EncodeToPHG;
例1:
string path=Application.persistentDataPath+"/wukuaTurret.jpg";
public Material image;
IEnumerator getTexture2d(){
yield return new WaitForEndOfFrame();
Texture2D t = new Texture2D(200, 180);
t.ReadPixels(new Rect(200, 320, 200, 180), 0, 0, false);
t.Apply();
byte[] byt = t.EncodeToPNG();
System.IO.File.WriteAllBytes(path, byt);
}
IEnumerator getCaptureFf(){
path=Application.persistentDataPath;
Debug.Log("path"+path);
www=new WWW("file://"+path+"/Screenshot.png");
yieldreturn www;
image.mainTexture=www.texture;
}
好好 好那个东西 谢谢分享
感谢楼主的无私分享!{:soso__11402694654016840197_7:} 真心顶 说的非常好 很好哦 不错不错 LZ真是人才 很不错 顶顶多好
页:
[1]