您的位置:首页 > 移动开发 > Unity3D

Unity发布安卓平台——截屏保存到安卓目录方法

2016-08-23 13:57 981 查看
 IEnumerator ScreenShotMethod(Rect rect)

    {

        yield return new WaitForEndOfFrame();

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

        png.ReadPixels(rect, 0, 0);

        png.Apply();

        byte[] bytes = png.EncodeToPNG();

        //安卓设备保存路径。必须     /sdcard/DCIM/xxx;

        string destin = "/sdcard/DCIM/Screenshots";

        //检查是否存在文件夹,不存在则创建。

        if (!Directory.Exists(destin))

        {

            Directory.CreateDirectory(destin);

        }

        string pathSave = destin + "/liiuu.png";

        System.IO.File.WriteAllBytes(pathSave, bytes);

    }

这里面最重要的是安卓下路径格式 /sdcard/DCIM      另外需要加上创建文件夹的方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: