免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
從Unity Game在Android應(yīng)用程序上共享圖像

玩家死亡時(shí),我已經(jīng)在游戲中捕獲了屏幕截圖.我正在按照以下代碼捕獲屏幕快照.

RenderTexture rt = new RenderTexture (800, 600, 24);    MainCamera.targetTexture = rt;    Texture2D texture = new Texture2D (800, 600, TextureFormat.RGB24, false);    MainCamera.Render ();    RenderTexture.active = rt;    texture.ReadPixels (new Rect (0, 0, 800, 600), 0, 0);    MainCamera.targetTexture = null;    RenderTexture.active = null;    Destroy (rt);    byte[] bytes = texture.EncodeToPNG ();    Directory.CreateDirectory (Application.persistentDataPath   "/GameOverScreenShot");    File.WriteAllBytes (Application.persistentDataPath   "/GameOverScreenShot"   "/DiedScreenShot.png", bytes);

我正在使用以下代碼保存屏幕截圖.

byte[] bytes = File.ReadAllBytes (Application.persistentDataPath  "/GameOverScreenShot"   "/BirdDiedScreenShot.png");Texture2D texture = new Texture2D (800, 600, TextureFormat.RGB24, false);RectOffset tempOffset = new RectOffset (5, 5, 5, 5);texture.filterMode = FilterMode.Trilinear;texture.LoadImage (bytes);Sprite sprite = Sprite.Create (texture, new Rect (0, 0, 800, 400), new Vector2 (0.5f, 0.0f), 2.0f);ScreenShot_Image.GetComponent<Image> ().sprite = sprite;

現(xiàn)在,我想在Android應(yīng)用程序上共享此屏幕截圖.根據(jù)我的研究,我已經(jīng)獲得了以下代碼,但是它返回的是空白圖像.

//instantiate the class IntentAndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");//instantiate the object IntentAndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");//call setAction setting ACTION_SEND as parameterintentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));//instantiate the class UriAndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");//instantiate the object Uri with the parse of the url's filestring destination = Application.persistentDataPath   "/GameOverScreenShot"   "/DiedScreenShot.png";AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse","file://" destination);//call putExtra with the uri object of the fileintentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);//set the type of fileintentObject.Call<AndroidJavaObject>("setType", "image/*");//instantiate the class UnityPlayerAndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");//instantiate the object currentActivityAndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");//call the activity with our IntentcurrentActivity.Call("startActivity", intentObject);

在這方面我應(yīng)該改變什么?請(qǐng)幫助,提前謝謝

解決方法:

只需調(diào)用takeScreenShotAndShare()即可截屏并共享它.如果您已經(jīng)有要共享的圖像,只需調(diào)用StartCoroutine(shareScreenshot(path));.并傳遞圖像的路徑/位置.這僅支持png圖像.要共享jpeg,請(qǐng)更改

intentObject.Call<AndroidJavaObject>("setType", "image/png");

intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");

整個(gè)代碼:

void takeScreenShotAndShare(){    StartCoroutine(takeScreenshotAndSave());}private IEnumerator takeScreenshotAndSave(){    string path = "";    yield return new WaitForEndOfFrame();    Texture2D screenImage = new Texture2D(Screen.width, Screen.height);    //Get Image from screen    screenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);    screenImage.Apply();    //Convert to png    byte[] imageBytes = screenImage.EncodeToPNG();    System.IO.Directory.CreateDirectory(Application.persistentDataPath   "/GameOverScreenShot");    path = Application.persistentDataPath   "/GameOverScreenShot"   "/DiedScreenShot.png";    System.IO.File.WriteAllBytes(path, imageBytes);    StartCoroutine(shareScreenshot(path));}private IEnumerator shareScreenshot(string destination){    string ShareSubject = "Picture Share";    string shareLink = "Test Link"   "\nhttps://stackoverflow.com/questions/36512784/share-image-on-android-application-from-unity-game";    string textToShare = "Text To share";    Debug.Log(destination);    if (!Application.isEditor)    {        AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");        AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");        intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));        AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");        AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://"   destination);        intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);        intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), textToShare   shareLink);        intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), ShareSubject);        intentObject.Call<AndroidJavaObject>("setType", "image/png");        AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");        AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");        currentActivity.Call("startActivity", intentObject);    }    yield return null;}
來(lái)源:https://www.icode9.com/content-1-504951.html
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Unity3D 開(kāi)發(fā)IPhone/Android 如何使用本地代碼(Object C/C++)
Unity3D調(diào)用第三方SDK(之一)從eclipse到Unity3D
Unity接入 百度語(yǔ)音識(shí)別 SDK!一篇文章搞定在Unity中實(shí)現(xiàn)語(yǔ)音識(shí)別!(萬(wàn)字完整教程)
unity 調(diào)用android函數(shù)
unity
Unity教程之
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服