Unity进行桌面截图并上传到服务器
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生成二维码
。。。。。
}
版权声明:本文为gan_2012原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。