Unity 入門教學:拍照,支持 Android、iOS、PC、MAC、Linux...
2014-09-17 12:31
591 查看
本範例共需兩個 Plane,一個是動態畫面預覽,另一個是拍照完畢顯示。
將本程式碼套用至其中一個 Plane,而另一個Plane 套用至本程式碼的 public GameObject g; 之中
運行後即可有效果。
本程式碼支持 PC 的 WebCam 網路攝影機、Android 與 iOS 的攝影機。
using UnityEngine;
using System.Collections;
public class MyCamera : MonoBehaviour {
public GameObject g;
WebCamTexture c;
void Start () {
c = new WebCamTexture (WebCamTexture.devices[0].name);
renderer.material.mainTexture = c;
c.Play ();
}
void OnGUI(){
if(GUI.Button(new Rect(0, 0, 100, 50), "拍照")){
Texture2D t = new Texture2D(c.width, c.height);
t.SetPixels(c.GetPixels());
t.Apply();
g.renderer.material.mainTexture = t;
// System.IO.File.WriteAllBytes("image.png", t.EncodeToPNG()); // 如果你要保存至硬碟or記憶卡的話
}
}
}
將本程式碼套用至其中一個 Plane,而另一個Plane 套用至本程式碼的 public GameObject g; 之中
運行後即可有效果。
本程式碼支持 PC 的 WebCam 網路攝影機、Android 與 iOS 的攝影機。
using UnityEngine;
using System.Collections;
public class MyCamera : MonoBehaviour {
public GameObject g;
WebCamTexture c;
void Start () {
c = new WebCamTexture (WebCamTexture.devices[0].name);
renderer.material.mainTexture = c;
c.Play ();
}
void OnGUI(){
if(GUI.Button(new Rect(0, 0, 100, 50), "拍照")){
Texture2D t = new Texture2D(c.width, c.height);
t.SetPixels(c.GetPixels());
t.Apply();
g.renderer.material.mainTexture = t;
// System.IO.File.WriteAllBytes("image.png", t.EncodeToPNG()); // 如果你要保存至硬碟or記憶卡的話
}
}
}
相关文章推荐
- iConvert Icons 图标转换生成利器,支持Windows, Mac OS X, Linux, iOS,和Android等系统
- iConvert Icons 图标转换生成利器,支持Windows, Mac OS X, Linux, iOS,和Android等系统
- 全平台最佳密码管理工具大全:支持 Windows、Linux、Mac、Android、iOS 以及企业应用
- 全平台最佳密码管理工具大全:支持 Windows、Linux、Mac、Android、iOS 以及企业应用
- GuiLite-全平台UI框架(目前已经支持: iOS,Android, Linux, Windows,Mac,VR)
- Unity 使用C/C++ 跨平台终极解决方式(PC,iOS,Android,以及支持C/C++的平台)
- Unity 使用C/C++ 跨平台终极解决方案(PC,iOS,Android,以及支持C/C++的平台)
- Unity 使用C/C++ 跨平台终极解决方案(PC,iOS,Android,以及支持C/C++的平台)
- unity5.3.3 no pc,mac&linux standalone
- Unity播放视频(pc,android,ios)
- 在Quick-cocos2dx中使用云风pbc解析Protocol Buffers,支持win、mac、ios、android
- 在Quick-cocos2dx中使用云风pbc解析ProtocolBuffers,支持win、mac、ios、android
- 在Quick-cocos2dx中使用云风pbc解析Protocol Buffers,支持win、mac、ios、android
- Unity集成内嵌网页插件-支持Android和IOS
- Unity项目工程集成友盟分析统计SDK(支持iOS与Android平台)
- TeamViewer安装 windows linux MacOS chrome android ios
- unity基础开发----Unity获取PC,Ios系统的mac地址等信息
- iEmu:在Linux、Windows、Mac、Android系统上仿真运行iOS应用
- MP4是最值得你选用的格式,全平台通用windows、linux、ios、mac、android、H5
- 【lizhi125】Splashtop-超实用的免费跨平台远程桌面控制软件(支持Win/Mac/iOS/Android等)