Save rendertexture to image in file

Does anyone have the code to save a render texture to an image file. I’ve researched it a lot but can’t get it working e.g. converting it to Texture2D and then encoding to png.
Thanks

I think this ones been answered here

Check the documentation and example for Texture2D.EncodeToPNG. The example does just about what you want, with only a few minor modifications