/// <summary>
/// 生成相机照片并保存
/// </summary>
/// <param name="PhotographyCamera">相机</param>
/// <param name="imageMateData">图像宽高</param>
public void CreateCameraCaptureAndSaveLocal(Camera PhotographyCamera, int width, int height, string path)
{
RenderTexture rt = new RenderTexture(width, height, 16, RenderTextureFormat.ARGB32);
PhotographyCamera.targetTexture = rt;
PhotographyCamera.Render();
RenderTexture.active = rt;
Texture2D image = new Texture2D(width, height, TextureFormat.ARGB32, false);
image.ReadPixels(new Rect(0, 0, width, height), 0, 0);
image.Apply();
image.name = DateTime.Now.ToString();
//保存图像到本地文件夹中
if (string.IsNullOrEmpty(path))
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
//数据写入
byte[] bytes = image.EncodeToJPG();
if (bytes != null)
{
string savePath = path + "\\" + image.name + ".JPG";
System.IO.File.WriteAllBytes(savePath, bytes);
}
bytes = null;
}
}
标签:rt,Unity3d,image,bytes,height,相机,width,图像,path
From: https://blog.51cto.com/u_16221841/7260177