private void MakeCameraImg(Camera mCam, int width, int height)
{
//Image mImage;
RenderTexture rt = new RenderTexture(width, height, 0);
mCam.pixelRect = new Rect(0, 0, Screen.width, Screen.height);
mCam.targetTexture = rt;
Texture2D screenShot = new Texture2D(width, height,TextureFormat.RGB24, false);
mCam.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, width, height ), 0, 0);
mCam.targetTexture = null;
RenderTexture.active = null;
UnityEngine.Object.Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
string filename = Application.dataPath + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png";
System.IO.File.WriteAllBytes(filename, bytes);
}
unity3D 用RenderTexture截图
最新推荐文章于 2024-08-21 10:08:25 发布