Search Unity

Question How to make an export file button?

Discussion in 'Scripting' started by realmcrafter, Dec 10, 2020.

  1. realmcrafter

    realmcrafter

    Joined:
    Nov 12, 2020
    Posts:
    7
    I'm creating a game where the player can download an image after winning by pressing on a button. The image is an RawImage object. How do I do this? I couldn't find anything in how to do this online... Can someone help me?
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    So you want to write the image to a file. Something along those lines for Texture2D to PNG:
    https://answers.unity.com/questions/1567543/using-encodetopng-to-save-an-image-to-disk.html

    Just need to convert the Texture contained in RawImage to Texture2D
    https://stackoverflow.com/questions/58844351/converting-rendertexture-to-texture2d-in-unity-2019
    In the posted solution, just use Texture instead of RenderTexture, since that's the input CopyTexture expects anyways: https://docs.unity3d.com/ScriptReference/Graphics.CopyTexture.html

    There may be other and easier solutions for RawImage specifically but i never actually did this, so the above is pretty much just what google came up with.
     
  3. realmcrafter

    realmcrafter

    Joined:
    Nov 12, 2020
    Posts:
    7
    Thank you!