unity 项目文件夹保存哪2个_Unity3D里截图并保存在指定目录下

private void OnScreenCapture ()

{

//yield return new WaitForEndOfFrame();

try {

int width = Screen.width;

int height = Screen.height-reduceHigh;

Texture2D tex = new Texture2D (width, height, TextureFormat.RGB24, false);

tex.ReadPixels (new Rect (0, bottomStarH, width, height), 0, 0, true);

byte[] imagebytes = tex.EncodeToPNG ();

tex.Compress (false);

tex.Apply();

mScreenShotImgae = tex;

if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)

{

path = Application.persistentDataPath + screenShotFileName +".png";

string origin = path;

string destination = "/mnt/sdcard/moliputao";

if(!Directory.Exists(destination))

{

Directory.CreateDirectory(destination);

}

destination = destination + "/" + screenShotFileName +".png";

if(System.IO.File.Exists(origin))

{

System.IO.File.Move(origin,destination);

}

path = destination;

}

else if (Application.platform == RuntimePlatform.WindowsEditor) {

path = Application.dataPath;

path = path.Replace ("/Assets", "/"+screenShotFileName + ".png");

}

File.WriteAllBytes (path, imagebytes);

mScreenShotImgae = tex;

} catch (System.Exception e) {

Debug.Log ("ScreenCaptrueError:" + e);

}

}

只放出核心代码!以后有时间会补全和详细讲解!

因为我是需要截图后出现预览效果,所以并没有使用协程,如果用协程需要加一句代码,等待当前那一帧结束!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值