Unity怎么让截完图之后显示在游戏中 10
我想实现的功能是点击一个按钮可以截取此时的手机屏幕,之后将截取的这张图片显示在游戏中?请指教代码如何实现?...
我想实现的功能是点击一个按钮可以截取此时的手机屏幕,之后将截取的这张图片显示在游戏中?请指教代码如何实现?
展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏10(财富值+成长值)
展开全部
if (CaptureScreen)
{
//Vector3 Temp = gameObject.transform.position;
int iScreenW = Screen.width;
int iScreenH = Screen.height;
float scale = (float)iScreenH/iScreenW;
float fDefScale = 1.5f; //(float)960/640;
float [] array = new float[5];
if(scale >= fDefScale)
{
//rGameRect.width
array[1] = iScreenW;
//rGameRect.height
array[2]= fDefScale * iScreenW;
//rGameRect.left
array[3]= 0f;
//rGameRect.top
array[4]= (iScreenH - array[2])/2; //rGameRect.height)/2;
}
else{
//rGameRect.height
array[2]= iScreenH;
//rGameRect.width
array[1]= iScreenH / fDefScale;
//rGameRect.top
array[4]= 0f;
//rGameRect.left
array[3]= (iScreenW - array[1])/2; //rGameRect.width)/2;
}
Rect rGameRect = new Rect (array[3], array[4], array[1], array[2]);
//Rect rect = new Rect (0f, 0f, Screen.width, Screen.height);
//Texture2D screenShot = new Texture2D ((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
//screenShot.ReadPixels (rect, 0, 0);
Texture2D screenShot = new Texture2D ((int)rGameRect.width, (int)rGameRect.height, TextureFormat.RGB24, false);
screenShot.ReadPixels (rGameRect, 0, 0);
screenShot.Apply ();
CaptureScreen = false;
}
这段代码放到脚本中的OnPostRender函数中
然后将这个脚本挂到Camera上
截屏时改一下CaptureScreen为true;
截屏后是Texture2D类型 怎么用随你了
{
//Vector3 Temp = gameObject.transform.position;
int iScreenW = Screen.width;
int iScreenH = Screen.height;
float scale = (float)iScreenH/iScreenW;
float fDefScale = 1.5f; //(float)960/640;
float [] array = new float[5];
if(scale >= fDefScale)
{
//rGameRect.width
array[1] = iScreenW;
//rGameRect.height
array[2]= fDefScale * iScreenW;
//rGameRect.left
array[3]= 0f;
//rGameRect.top
array[4]= (iScreenH - array[2])/2; //rGameRect.height)/2;
}
else{
//rGameRect.height
array[2]= iScreenH;
//rGameRect.width
array[1]= iScreenH / fDefScale;
//rGameRect.top
array[4]= 0f;
//rGameRect.left
array[3]= (iScreenW - array[1])/2; //rGameRect.width)/2;
}
Rect rGameRect = new Rect (array[3], array[4], array[1], array[2]);
//Rect rect = new Rect (0f, 0f, Screen.width, Screen.height);
//Texture2D screenShot = new Texture2D ((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
//screenShot.ReadPixels (rect, 0, 0);
Texture2D screenShot = new Texture2D ((int)rGameRect.width, (int)rGameRect.height, TextureFormat.RGB24, false);
screenShot.ReadPixels (rGameRect, 0, 0);
screenShot.Apply ();
CaptureScreen = false;
}
这段代码放到脚本中的OnPostRender函数中
然后将这个脚本挂到Camera上
截屏时改一下CaptureScreen为true;
截屏后是Texture2D类型 怎么用随你了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询