Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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,590
    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!