unity调用摄像头拍照
来源:互联网 发布:罗兰电子鼓软件 编辑:程序博客网 时间:2024/05/21 15:41
我的unity调用摄像头拍照
因为做的是pc端的,所以不知道手机上效果是怎样的,据说代码是完全相同的。
废话不说,上代码,
打开摄像头代码:
/// <summary>/// Opens the camera/// </summary>/// <returns>The camera.</returns>IEnumerator OpenCamera(){yield return Application.RequestUserAuthorization (UserAuthorization.WebCam);if (Application.HasUserAuthorization (UserAuthorization.WebCam)) {WebCamDevice[] devices = WebCamTexture.devices;webCam = new WebCamTexture (devices [0].name, Screen.width, Screen.height, 12);image_userIcon.texture = webCam;webCam.Play ();}}保存图片代码如下:
/// <summary>/// Gets the texture2d./// </summary>/// <returns>The texture2d.</returns>IEnumerator GetTexture2d(){yield return new WaitForEndOfFrame();RectTransform rt = image_userIcon.GetComponent<RectTransform> ();Vector2 v2Min = new Vector2( rt.anchorMin.x * Screen.width,rt.anchorMin.y * Screen.height);Vector2 v2Max = new Vector2( rt.anchorMax.x * Screen.width,rt.anchorMax.y * Screen.height);Texture2D t = new Texture2D((int)(v2Max.x-v2Min.x),(int)(v2Max.y-v2Min.y));//要保存图片的大小//截取的区域t.ReadPixels(new Rect (v2Min.x,v2Min.y,(int)(v2Max.x-v2Min.x),(int)(v2Max.y-v2Min.y)),0,0,false);t.Apply();image_userIcon.texture = t;//把图片数据转换为byte数组byte[] byt = t.EncodeToPNG();//然后保存为图片File.WriteAllBytes(Application.dataPath + "/StreamingAssets/shexiang/" + Time.time + ".jpg", byt);webCam.Pause ();}运行完这段效果大概是这样滴:
阅读全文
0 0
- unity调用摄像头拍照
- unity调用摄像头拍照
- unity调用摄像头进行拍照和保存照片
- iOS_调用摄像头拍照
- android 调用摄像头拍照
- IOS 调用摄像头拍照
- Android 调用摄像头拍照
- 调用摄像头拍照
- 调用摄像头拍照
- 调用摄像头拍照 camera
- 调用摄像头拍照
- Android 调用摄像头拍照
- android: 调用摄像头拍照
- 调用摄像头 拍照
- VB 调用摄像头拍照,保存。
- android调用手机摄像头拍照
- Chrome浏览器调用摄像头拍照
- Android 调用摄像头功能【拍照】
- Python爬虫:HTTP协议、Requests库
- RecyclerView 应用
- Hibernate映射关系分析
- react-native项目移到mac上
- Goodbye, MulticoreWare Inc.
- unity调用摄像头拍照
- Sicily 1176. Two Ends
- centos 7关闭防火墙
- 内核源码--------page_address_init();
- ViewPager轮播图
- VIM高阶用法技巧
- Liferay 6.1开发学习:编译调试修改源码
- 为什么努力那么难-可心耳语(第三期)
- redhat EL6.5安装mysql5.7及常见问题