void CameraCapture(Camera m_Camera, string filename)
{
int width = Screen.width;
int height = Screen.height;
RenderTexture rt = new RenderTexture(width, height, 16);
m_Camera.targetTexture = rt;
m_Camera.Render();
RenderTexture.active = rt;
Texture2D t = new Texture2D(width, height);
t.ReadPixels(new Rect(0, 0, width, height), 0, 0);
t.Apply();
string path = CommonTool.Path(filename);
System.IO.File.WriteAllBytes(path, t.EncodeToJPG());
m_Camera.targetTexture = null;
}
public static string Path(string fileName) {
#if UNITY_EDITOR
return Application.dataPath + "/StreamingAssets/" + fileName;
#elif UNITY_IPHONE
return Application.dataPath+"/Ray/" + fileName;
#elif UNITY_ANDROID
return "jar:file://" + Application.dataPath + "!/assets/" + fileName;
#else
return Application.dataPath + "/StreamingAssets/" + fileName;
#endif
}
Unity 获取相机画面将其保存成图片
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 该Demo实现如下功能 从相册_照片 获取图片, 并贴在Image上 从相册_时刻 获取照片, 并贴在Image上...
- http://blog.csdn.net/anyuanlzh/article/details/50748928 h...
- https://blog.csdn.net/n_moling/article/details/78967502