I am trying to get a screen shot with ReadPixels and enlarge the resolution for output. I will be taking a subsection (cropping it) before saving as a png to disk, so i can’t rely on the Application.CaptureScreenshot method.
The problem i am experiencing is the enlarged output is highly distorted Some portions are squished, while others are stretched. Attached are an unscaled and scaled example to show the distortion.
any help would be appreciated.
below is my function in javascript:
function screen_grab3(png_name:String, cam:Camera){
yield WaitForEndOfFrame();
//set render size and make texture
var scale:float=4;
var r_width:int=scale*Mathf.Floor(cam.pixelWidth);
var r_height:int=scale*Mathf.Floor(cam.pixelHeight);
var scaled_rt:RenderTexture=new RenderTexture(r_width, r_height, 24);
//make 2d texture for writing to
var screen_grab:Texture2D=new Texture2D(r_width, r_height, TextureFormat.RGB24, false);
// set cam to render to the texture
cam.targetTexture=scaled_rt;
cam.Render();
RenderTexture.active=scaled_rt;
//write screenshot
screen_grab.ReadPixels(new Rect(0, 0, r_width, r_height), 0, 0);
screen_grab.Apply();
//revert cam settings
cam.targetTexture=null;
RenderTexture.active=null;
//convert to png
var bytes=screen_grab.EncodeToPNG();
//destroy stuff
Destroy (screen_grab);
//Destroy(scaled_rt);
//save to file
var path:String=Application.persistentDataPath+"/"+png_name+".png";
File.WriteAllBytes(path, bytes);
}