Unity3D 截屏功能
2015-05-23 13:53
218 查看
private Texture tex2D;
private IEnumerator CutScreen()
{
string SavePath = Application.persistentDataPath;
#if UNITY_EDITOR
SavePath = Application.dataPath;
#endif
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
yield return new WaitForEndOfFrame();
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);
File.WriteAllBytes(SavePath + "/../SavedScreen.png", bytes);
yield return null;
//读取图片//
string Url = "file://" + SavePath + "/../SavedScreen.png";
WWW www = new WWW(Url);
yield return www;
if (www.error != null)
{
Debug.LogError(www.error);
}
tex2D = www.texture;
****************************************************************************************
//显示图片//
建一个父panel
GameObject photo = new GameObject("ScreenshotObj");
UITexture uiTexture = photo.AddComponent<UITexture>();
uiTexture.mainTexture = tex2D;
photo.layer = NGUI摄像机的layer;
photo.transform.parent = 父panel.transform;
photo.transform.localPosition = xxxxxx;
photo.transform.localScale = xxxxx;
uiTexture.width = xxx;
uiTexture.height=xxx;
uiTexture.depth=NGUIToos.CalculateNextDepth(父panel.gameObject);
******************************************************************************************
}
private IEnumerator CutScreen()
{
string SavePath = Application.persistentDataPath;
#if UNITY_EDITOR
SavePath = Application.dataPath;
#endif
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
yield return new WaitForEndOfFrame();
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);
File.WriteAllBytes(SavePath + "/../SavedScreen.png", bytes);
yield return null;
//读取图片//
string Url = "file://" + SavePath + "/../SavedScreen.png";
WWW www = new WWW(Url);
yield return www;
if (www.error != null)
{
Debug.LogError(www.error);
}
tex2D = www.texture;
****************************************************************************************
//显示图片//
建一个父panel
GameObject photo = new GameObject("ScreenshotObj");
UITexture uiTexture = photo.AddComponent<UITexture>();
uiTexture.mainTexture = tex2D;
photo.layer = NGUI摄像机的layer;
photo.transform.parent = 父panel.transform;
photo.transform.localPosition = xxxxxx;
photo.transform.localScale = xxxxx;
uiTexture.width = xxx;
uiTexture.height=xxx;
uiTexture.depth=NGUIToos.CalculateNextDepth(父panel.gameObject);
******************************************************************************************
}
相关文章推荐
- Android实现截屏和截长图功能的几种方法
- Android系统截屏功能提取
- Unity3D界面功能操作讲解
- android视图截屏功能
- [原创]unity3D学习【功能实现】之五:在图片上显示文字或名字,可更改text mesh
- [原创]unity3D学习【功能实现】之三:实例化
- Unity3d 截屏之后转换成Texture2d
- android 5.1状态栏添加截屏功能
- [unity3d]unity聊天功能
- Android 视频播放器截屏功能实现讲解
- Unity3D 之武器系统冷却功能的实现方式
- iPhone 应用里实现截屏功能的代码
- cocos2dx 3.2截屏功能
- [Unity3d]unity+asp.net实现动态搜索加载模型并且能够实现模型拖动缩放的功能
- Android实现截屏并保存操作功能
- 截屏功能
- Win10即将迎来新功能,让玩家“更爽”_广州达内Unity3D培训机构
- 【代码笔记】iOS-截屏功能
- unity3d中平滑跟随的功能实现!!!!
- android cocos2dx游戏-添加截屏并分享微博功能