You can render to a texture and then use the texture data to create an image as shown here: How to read pixels of texture?
4K x 4K is possible pending on the platform due to VRAM and device limitations. 1K x 1K and 2K x 2K are ‘safer’ dimensions to use.