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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can I make Unity Generate a PNG image?

Discussion in 'Scripting' started by Gousenfire, Feb 2, 2018.

  1. Gousenfire

    Gousenfire

    Joined:
    Feb 18, 2014
    Posts:
    30
    Hello World,

    So I'm creating a board game that use cards most of the time during its gameplay. So I created a small and very simple way to use the Scriptable Objects in Unity to store the data of all my cards and see a preview of them just swaping the objects using the new UI System. But I wonder if it would be to hard to render thouse cards in a PNG file it would make my entire life to much easer.

    Thanks for all,

    Cheers.

    PS: I don't know if this is the right place to post this thread so please move it for me if it's not the case
     
  2. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
  3. Gousenfire

    Gousenfire

    Joined:
    Feb 18, 2014
    Posts:
    30
    Well it helps a bit cause now I know that Unity has a method that encodes Textures to PNG but I cant take a shoot of the screen cause it could have different sizes and there for it would cause that my cards would have different sizes depending on the person who builds them.

    I have another question as well....
    As I'm using the UI System to create my cards layout would I have to use them to build it? Is there another way to do it?
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Then restrict your users design area to the size of a card. That's simple enough to do.
     
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    One way you might be able to do this would be to use a camera to render into a RenderTexture, and save that texture data for display later. You would just need to configure the resolution/format of the render texture, and position/size the camera to frame the shot correctly. That would be nice because you can set culling flags on the camera to only see the things that are relevant for the "thumbnail" so to speak.

    Not sure the specifics of how that would be implemented but I think that would work.
     
  6. Gousenfire

    Gousenfire

    Joined:
    Feb 18, 2014
    Posts:
    30
    I think would be best if I create a software from scratch. Any suggestion?
     
  7. OuterCloud

    OuterCloud

    Joined:
    Jun 8, 2019
    Posts:
    3
    You might be able to create a file with .png or .bmp extension in a resources folder and write color data to that in the png format and load that file through script by using var texture = Resources.Load<Texture2D>("texture01");