Dear Friends:
I’ve been taking screenshots with a script that includes this:
// Wait for the frame to finish drawing:
yield return new WaitForEndOfFrame();
// Create a texture the size of the screen, RGB24 format
float width = Screen.width;
float height = Screen.height;
Texture2D tex = new Texture2D( (int) (width), (int) (height), TextureFormat.RGB24, false );
// Read screen contents into the texture
tex.ReadPixels( new Rect(0f, 0f, width, height), 0, 0 );
tex.Apply();
And that’s great, it’s working, beautiful. But I also need to have a Thumbnail size screenshot to be stored and called up as the player is in the menu of saved games.
Any ideas on how to make a small screenshot like that?
Thanks.
I’m interested in this question too. Did you find a solution?
I haven’t tried it, but I see from the doc:
Texture2D.Resize
I have just came across this old thread.
But making a thumbnail just can not be any simpler than assigning the target size at start like that:
Camera currentCamera = Camera.main;
int tw = 200; //thumb width
int th = 180; //thumb height
RenderTexture rt = new RenderTexture(tw, th, 24, RenderTextureFormat.ARGB32);
rt.antiAliasing = 4;
currentCamera.targetTexture = rt;
currentCamera.Render();//
//Create the blank texture container
Texture2D thumb = new Texture2D(tw, th, TextureFormat.RGB24, false);
//Assign rt as the main render texture, so everything is drawn at the higher resolution
RenderTexture.active = rt;
//Read the current render into the texture container, thumb
thumb.ReadPixels(new Rect(0, 0, tw, th), 0, 0, false);
byte[] bytes = thumb.EncodeToJPG(90);
Object.Destroy(thumb);
// For testing purposes, also write to a file in the project folder
File.WriteAllBytes(Application.dataPath + "/SavedThumb.jpg", bytes);
//--Clean up--
RenderTexture.active = null;
currentCamera.targetTexture = null;
rt.DiscardContents();
No need for any rescaling.
1 Like