赞
踩
private string uplaodURL = "http://xxx.xxx.xxx.xxx/UploadImage.aspx"; void Start () { ScreenShot (); } public void ScreenShot(){ StartCoroutine (waitScreenShot()); } IEnumerator waitScreenShot(){ yield return new WaitForEndOfFrame (); //新建2D纹理 Texture2D texture2D = new Texture2D (400, 200, TextureFormat.RGB24, false); //读取屏幕相应的像素点 texture2D.ReadPixels (new Rect(100, 100, 400, 200), 0, 0, true); texture2D.Apply (); //2D纹理转成Png图片格式 byte[] bytes = texture2D.EncodeToPNG (); //保存到本地目录 File.WriteAllBytes (Application.dataPath + "/screenShot.png",bytes); //http上传图片到相应服务器 WWWForm wwwForm = new WWWForm (); wwwForm.AddBinaryData ("post", bytes); WWW www = new WWW (uplaodURL, wwwForm); //启动协程等待服务器返回参数图片URL StartCoroutine (postImage (www)); } IEnumerator postImage(WWW www){ yield return www; print(www.text); //获取图片的URL生成二维码 。。。。。 }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。