Search Unity

Possible to export an image of scene/game view, in defined resolution?

Discussion in 'Editor & General Support' started by rpuls, Nov 10, 2019.

  1. rpuls

    rpuls

    Joined:
    Feb 3, 2017
    Posts:
    101
    I find it insanely time consuming to supply screenshots for the iOS app store as they MUST be of iOS device resolution. It takes soooo much time to build and run on all devices, take screenshots and upload. And then the next day you notice a typo and have to redo that full hour of work. Not to mention for each little update you start slacking on updating your screenshots because it is simple too time consuming. There must be someone before me that found a faster/better way of doing so.

    I am looking for a way within the unity editor to just export a image of what every is in my game view, but in a defined resolution. I did find one plugin that were supposed to do this, but for some reason it only works for a camera? not a canvas, not replicating what is in the actual game view.
     
  2. cristianm_unity

    cristianm_unity

    Unity Technologies

    Joined:
    Oct 16, 2018
    Posts:
    259
    Hi @rpuls!

    Please take a look at this method: https://docs.unity3d.com/ScriptReference/ScreenCapture.CaptureScreenshot.html

    What it does is to capture a Screenshot of your game, the following Script will add a Menu to the Editor so you can capture an image.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. public class ScreenshotGrabber
    6. {
    7.     [MenuItem("Screenshot/Grab")]
    8.     public static void Grab()
    9.     {
    10.         ScreenCapture.CaptureScreenshot("Screenshot.png", 1);
    11.     }
    12. }
    13. #endif
    You just need to adjust the resolution of your game view and hit Screenshot > Grab.
    The second parameter will allow you to scale the resulting image, so if you set it to 1, you will get an image at the exact resolution of your game view, if you set it to 2, you will get an image scaled two times.
     
  3. Viperace

    Viperace

    Joined:
    Dec 26, 2015
    Posts:
    4
    I have to ask, where is the file "Screenshot.png" being saved at ?

    I am talking about using this function in Unity Editor, while playing Game View
     
  4. Kheremos

    Kheremos

    Joined:
    Dec 13, 2017
    Posts:
    17
    It's saved in the project root. If, for some reason, you want it more readily accessible in the editor, you can prefix the screenshot name with "Assets" like

    Code (CSharp):
    1. ScreenCapture.CaptureScreenshot("Assets/Screenshot.png", 1);
    I modified the handy ScreenshotGrabber class a little for my purposes:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEditor;
    3.  
    4. public class ScreenshotGrabber
    5. {
    6.     [MenuItem("Screenshot/Grab")]
    7.     public static void Grab()
    8.     {
    9.         ScreenCapture.CaptureScreenshot("Screenshot" + GetCh() + GetCh() + GetCh() +  "_" + Screen.width+"x"+Screen.height+".png", 1);
    10.     }
    11.  
    12.     public static char GetCh()
    13.     {
    14.         return (char)UnityEngine.Random.Range('A', 'Z');
    15.     }
    16. }
    17. #endif
    I wanted to take multiple screenshots at various resolutions to provide to a store listing. Pretty common scenario.