欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

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

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

開(kāi)通VIP
Unity中關(guān)于保存圖片到Android/IOS相冊中的問(wèn)題

       我們在一些項目中可能需要截圖保存功能(特別是AR的一些項目),將截下來(lái)的圖保存的相冊中,從而實(shí)現分享功能。下面就Android和IOS說(shuō)一下他們是如何將圖片保存到本地圖冊的。

關(guān)于安卓端,保存到相冊方法很簡(jiǎn)單,就是也路徑的問(wèn)題,具體方法如下:

public class takephoto : MonoBehaviour{    private int i = 0;    //UI    public GameObject[] btn;    //存儲路徑    private string Path_save;    //讀取路徑    private string Path_read;    private string filepath;    private string destination;    void Start()    {        filepath = Application.persistentDataPath + "/test.txt";    }    void OnClick()    {        StartCoroutine(getTexture2d());    }    IEnumerator getTexture2d()    {        //隱藏UI        for (int j = 0; j < btn.Length; j++)        {            btn[j].GetComponentInChildren<UISprite>().enabled = false;        }        //截圖操作        yield return new WaitForEndOfFrame();        Texture2D t = new Texture2D(Screen.width, Screen.height,TextureFormat.RGB24,false);        //顯示UI        for (int j = 0; j < btn.Length; j++)        {            btn[j].GetComponentInChildren<UISprite>().enabled = true;        }        t.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, true);        byte[] bytes = t.EncodeToPNG();        t.Compress(true);        t.Apply();        //獲取系統時(shí)間        System.DateTime now = new System.DateTime();        now = System.DateTime.Now;        string filename = string.Format("image{0}{1}{2}{3}.png", now.Day, now.Hour, now.Minute, now.Second);        //記錄每一個(gè)截圖名字        StreamWriter sw;        FileInfo ft = new FileInfo(filepath);        if (!ft.Exists)        {            sw = ft.CreateText();        }        else        {            sw = ft.AppendText();        }        sw.WriteLine(filename);        sw.Close();        sw.Dispose();        //應用平臺判斷,路徑選擇        if (Application.platform == RuntimePlatform.Android)        {            string origin = Path_save;            destination = "/mnt/sdcard/DCIM/ARphoto";            if (!Directory.Exists(destination))            {                Directory.CreateDirectory(destination);            }            destination = destination + "/" + filename;            Path_save = destination;               }        //保存文件        File.WriteAllBytes(Path_save, bytes);    }}



其中主要的就是安卓相冊的一個(gè)路徑問(wèn)題,我是在相冊路徑下,新建了一個(gè)名叫ARphoto相冊,所有保存下來(lái)的圖片都保存在這個(gè)相冊中,可以再圖庫應用中查看到這個(gè)相冊文件夾。


在IOS端保存相冊是無(wú)法單獨在Unity中完成的。需要調用Xcode中的方法,關(guān)于Unity與Xcode之間的交互有什么疑問(wèn)的可以查看我之前寫(xiě)的 博文http://blog.csdn.net/hasion/article/details/43668229

其具體實(shí)現方法如下:

public class TakePhoto : MonoBehaviour{[DllImport("__Internal")]private static extern void _SavePhoto (string readaddr);private string path_save;private string path_read;public GameObject _demoBtns;void OnClick (){this.GetComponentInChildren<UITexture> ().enabled = false;_demoBtns.SetActive (false);System.DateTime now = System.DateTime.Now;string filename = string.Format ("image{0}{1}{2}{3}{4}{5}.png", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);path_save = filename;path_read = Application.persistentDataPath + "/" + path_save;//set photomanager.csif (!string.IsNullOrEmpty (path_save)) {PhotosManager.GetInstance ().PhotoPath = path_read;}StartCoroutine (SavePhoto ());}IEnumerator SavePhoto (){yield return new WaitForSeconds (0.2f);Application.CaptureScreenshot (path_save);yield return new WaitForSeconds (0.5f);this.GetComponentInChildren<UITexture> ().enabled = true;_demoBtns.SetActive (true);yield return new WaitForSeconds (1.2f);_SavePhoto (path_read);}}

Xcode中執行文件如下:

#import "PhotoManager.h"@implementation PhotoManager- ( void ) imageSaved: ( UIImage *) image didFinishSavingWithError:( NSError *)error          contextInfo: ( void *) contextInfo{    if (error != nil)    {        NSLog(@"有錯誤");    }    else    {        NSLog(@"保存結束");    }}void _SavePhoto(char *readAddr){    NSString *strReadAddr = [NSString stringWithUTF8String:readAddr];    UIImage *img = [UIImage imageWithContentsOfFile:strReadAddr];    NSLog(@"%@",[NSString stringWithFormat:@"w:%f, h:%f", img.size.width, img.size.height]);    NSLog(@"%@",[NSString stringWithFormat:@"%s",readAddr ]);    PhotoManager *instance = [PhotoManager alloc];    UIImageWriteToSavedPhotosAlbum(img, instance,                                   @selector(imageSaved:didFinishSavingWithError:contextInfo:), nil);}@end


大體執行流程就是這樣的,有什么錯誤或者建議的地方,歡迎大家指正,謝謝?。?!





關(guān)于Unity中的Update、Lateupdate和FixedUpdate。
MonoBehaviour.Update更新當MonoBehaviour啟用時(shí),其Update在每一幀被調用。MonoBehaviour.FixedUpdate固定更新當MonoBehaviour啟用時(shí),其FixedUpdate在每一幀被調用。處理Rigi

Unity3D時(shí)間順序與功能
Unity3D中所有控制腳本的基類(lèi)MonoBehaviour有一些虛函數用于繪制中事件的回調,也可以直接理解為事件函數,例如大家都很清楚的Start,Update等函數,以下做

Unity+Mono斷點(diǎn)調試步驟
項目制作過(guò)程中,我們可能要用到斷點(diǎn)調試來(lái)檢測程序運行過(guò)程中的實(shí)時(shí)數據,從而檢測出程序出錯的位置。具體步驟如下:1、Mono必須是Unity安裝時(shí)自

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Unity3D研究之支持中文與本地文件的讀取寫(xiě)入
Unity3D研究院之Android全自動(dòng)打包生成apk(六十九) | 雨松MOMO程序研究院
如何在Unity中使用剪貼板/粘貼板
android發(fā)送郵件
Unity3D研究院之IOS&Android收集Log文件(六十二) | 雨松MOMO程序研究院
Unity 實(shí)現簡(jiǎn)單的語(yǔ)音聊天 [Android版本]
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久