当前位置:   article > 正文

Unity进行桌面截图并上传到服务器记录_unity3d上传图片到服务器

unity3d上传图片到服务器

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生成二维码
		。。。。。
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/783254
推荐阅读
相关标签
  

闽ICP备14008679号