public void SaveTexture2Local(Texture2D tex, string savePath = "")
{
//保存本地
Byte[] bytes = tex.EncodeToPNG();
SaveTexture2Local(bytes,savePath);
}
public void SaveTexture2Local(byte[] bytes, string savePath="")
{
string dpath = string.IsNullOrEmpty(savePath) == true ? Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/截图/" : savePath;
if (Directory.Exists(dpath) == false)
{
Directory.CreateDirectory(dpath);
}
Debug.Log($"截图目录{dpath}");
string fileName = $"{dpath}ScreenShot{System.DateTime.Now.Month}_{System.DateTime.Now.Day}_{System.DateTime.Now.Hour}_{System.DateTime.Now.Minute}_{System.DateTime.Now.Second}.png";
File.WriteAllBytes(fileName, bytes);
}
文章来源地址https://www.toymoban.com/news/detail-744391.html
文章来源:https://www.toymoban.com/news/detail-744391.html
到了这里,关于Unity 保存图片到本地的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!