Unity3d 截屏并上传到服务器
来源:互联网 发布:淘宝介入售后 退货拒收 编辑:程序博客网 时间:2024/06/06 11:45
最近项目所需,需要捕抓图像并上传到服务器。
参考了别人的文章,加以改动。
写此博客以记录。
参考博客
设置全局变量
public Camera cutFrameCamer;Rect canvas;
开始截图
canvas.Set(0, 0, Screen.width, Screen.height);//设置画布大小等于当前屏幕的宽和高。 CaptureScreen(cutFrameCamer, canvas); 执行截屏方法。
截屏并上传
public void CaptureScreen(Camera c, Rect r) {
//捕抓摄像机图像并转换成字符数组 RenderTexture rt = new RenderTexture((int)r.width, (int)r.height, 0); c.targetTexture = rt; c.Render(); RenderTexture.active = rt; Texture2D screenShot = new Texture2D((int)r.width, (int)r.height, TextureFormat.RGB24, false); screenShot.ReadPixels(r, 0, 0); screenShot.Apply(); c.targetTexture = null; RenderTexture.active = null; GameObject.Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG(); string url = "http://xxxxxxxxxxxxxxxxx";//要上传到的地址 WWWForm form = new WWWForm(); form.AddField("filename", fileName); form.AddBinaryData("photo", bytes);//把图片流上传
WWW www = new WWW(url, form); StartCoroutine(PostData(www));//启动子线程 Destroy(screenShot);//销毁 }迭代器 等待服务器返回
IEnumerator PostData(WWW www) { yield return www; Debug.Log(www.text);//输出服务器返回结果。 }
0 0
- Unity3d 截屏并上传到服务器
- PHP上传文件到服务器 并显示
- service 电话监听器并上传到服务器
- PhoneGap 拍照并上传到远程服务器
- 捕获异常信息并上传到服务器
- Android图片压缩并上传到服务器
- Unity3d 工具打包完 自动上传到FTP服务器
- php上传图片到服务器&&上传excel到服务器并写入MySQL
- 使用canvg截屏上传至服务器并返回二维码
- ASP.NET 上传图片到服务器并查询
- mysql数据库自动备份并上传到服务器
- HTML5在线摄像头拍照上传并保存到服务器
- 上传文件并保存到另外一台服务器
- 使用maven打包项目并上传到Linux服务器
- 图片(bitmap)转化为byte[],并上传到服务器
- 使用 html5 FileReader 获取图片, 并异步上传到服务器
- struts2 图片上传到服务器并显示在页面
- 读取excel文档保存服务器并上传到…
- 安装qtceator后无法启动help插件 Qt编译错误:cannot find -lGL 解决办法
- IGAME
- 索引器实验
- linux安装mysql
- java web开发_购物车功能实现
- Unity3d 截屏并上传到服务器
- leetcode-520-Detect Capital
- PAT甲级C语言.1001. 害死人不偿命的(3n+1)猜想
- Tacker部署与使用详解
- 扩展卡尔曼滤波器的原理及应用
- Spring声明式事务管理、事务的传播行为xml配置
- Git使用教程
- adb 提示:error: unknown host service解决方法
- 进程与线程的一个简单解释