Development Unity

How to take Screen Shot in Particular Area in unity

i am using unity 2018. In my project i have to take particular area screen. I have using the below code. It is working. But The exact image is not working. It goes some extent. How can i take the exact image.

   using UnityEngine;
   using System.Collections;
   using System;

  public class ScreenCapture : MonoBehaviour
  public RenderTexture overviewTexture;
  GameObject OVcamera;
  public string path = "";

  void Start()
  OVcamera = GameObject.FindGameObjectWithTag("OverviewCamera");
  void LateUpdate()
 if (Input.GetKeyDown("f9"))
// return file name
 string fileName(int width, int height)
 return string.Format("screen_{0}x{1}_{2}.png",
 width, height,

 public IEnumerator TakeScreenShot()
 yield return new WaitForEndOfFrame();

 Camera camOV =;  
 RenderTexture currentRT =; = camOV.targetTexture;
 Texture2D imageOverview = new Texture2D(camOV.targetTexture.width, camOV.targetTexture.height, 
 TextureFormat.RGB24, false);
 imageOverview.ReadPixels(new Rect(0, 0, camOV.targetTexture.width, camOV.targetTexture.height), 0, 
 imageOverview.Apply(); = currentRT;           
 byte[] bytes = imageOverview.EncodeToPNG();

     // save in memory
 string filename = fileName(Convert.ToInt32(imageOverview.width), 
 path = Application.persistentDataPath + "/Snapshots/" + filename;       
 System.IO.File.WriteAllBytes(path, bytes);

this is my above code..

Leave a Reply

Your email address will not be published. Required fields are marked *