Unity 获取截屏 并且呼起微信分享

来源:互联网 发布:三棱镜折射率测量数据 编辑:程序博客网 时间:2024/06/17 15:29

直接本上代码。

    IEnumerator GetScreenshot()    {         // 截屏1帧后再呼起微信        yield return new WaitForEndOfFrame();        string imgPath = System.IO.Path.Combine(Application.persistentDataPath, "Screenshot.jpg");        int width = Screen.width;        int height = Screen.height;        Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);        tex.Apply();        System.IO.File.WriteAllBytes(imgPath, tex.EncodeToJPG());        PaiShareUrl = imgPath;        //0 session        //1 timeline        string shareType = "0";        Debug.Log("分享截图:" + imgPath);#if UNITY_IOS || UNITY_IPHONE        _WXSharePicture("", "", "", shareType, imgPath);#elif UNITY_ANDROID        AndroidJavaClass jc = new AndroidJavaClass(Defines.APP_UNITY_CLASS);        AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");        jo.Call("_WXSharePicture", new string[] { "", "", "", shareType, imgPath });#endif    }

android 和 ios 实现看官方文档,点这里。