unity IOS 截图保存 黑色图片

weixin_39412599 2017-07-24 09:38:00
 
[DllImport("__Internal")]
private static extern void _SavePhoto(string readAddr);
public void Stt()
{
//获取系统时间并命名相片名
System.DateTime now = System.DateTime.Now;
string times = now.ToString();
times = times.Trim();
times = times.Replace("/", "-");
string filename = "Screenshot" + times + ".png";
string Path_save;
//判断是否为IOS平台
if (Application.platform == RuntimePlatform.IPhonePlayer)
{

//截取屏幕
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
//转为字节数组
byte[] bytes = texture.EncodeToPNG();



string destination = Application.persistentDataPath;


Path_save = destination + "/" + filename;
//存图片
File.WriteAllBytes(Path_save, bytes);
var readAddr = Path_save;
_SavePhoto(readAddr);

}
}

我在unity里是这样写的,做成按钮的click
————————————————————————————————————————
在Xcode里加了下面两个脚本




拍照后在相册中查看,全是存的黑色图片,是为啥啊?好痛苦
...全文
550 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhizun123456 2021-01-12
  • 打赏
  • 举报
回复
截图的方法在协程里

8,304

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧