Unity+NGUI实现截图加上传

IEnumerator CaptureScreenshot2(Rect rect)
    {
        // 先创建一个的空纹理,大小可根据实现需要来设置  
        Texture2D screenShot = new Texture2D(Screen.width, Screen.height/*, TextureFormat.RGB24, false*/);
        canvas.SetActive(false);//屏蔽UI
        yield return new WaitForEndOfFrame();
        // 读取屏幕像素信息并存储为纹理数据,  
        screenShot.ReadPixels(rect, 0, 0);
        screenShot.Apply();

        // 然后将这些纹理数据,成一个png图片文件  
        byte[] bytes = screenShot.EncodeToPNG();
        canvas.SetActive(true); 
        //-----本地创建图片
        string filename = Application.dataPath + "/Screenshot.png";
        System.IO.File.WriteAllBytes(filename, bytes);
        Debug.Log(string.Format("截屏了一张图片: {0}", filename));
        //-----网路创建图片
        string tempS = System.Convert.ToBase64String(bytes);
        WWWForm form = new WWWForm();
        form.AddField("image",tempS);
        WWW www = new WWW("http://project.weily.org/uim/index.php", form);
        yield return www;
        print(www.text);
        //-----在NGUI3XX的版本下,将路径复制到剪贴板
        TextEditor te = new TextEditor();
        te.content = new GUIContent("http://project.weily.org/uim/" + www.text);
        te.OnFocus();
        te.Copy();
    }  


笔记笔记~

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值