-2
\$\begingroup\$

I want to save my game as a PNG file. Which parts should I include in the file?

Should I include the alpha channel, EXIF data, or something else?

\$\endgroup\$
5
  • 3
    \$\begingroup\$ Maybe it would help to tell us why you want to do such a thing..? \$\endgroup\$
    – Vaillancourt
    Dec 29, 2023 at 19:15
  • 2
    \$\begingroup\$ I once had to encode binary data in images to demonstrate bypassing a firewall. If you use RGB24 or RGBA32, each channel can represent one byte per pixel and fairly cleanly. That said, you can use literally any format and encoding, so long as your reading/writing code adopt the same standard. I can't imagine why you'd want to do this in a game? \$\endgroup\$
    – Basic
    Dec 29, 2023 at 19:50
  • 1
    \$\begingroup\$ Do you want to save your data as stenography behind an original image, should the save file generate an image or what do you expect the png to represent? The parts you should include are the same as for any other save file: everything that is needed for your game to recreate the saved state, whatever that means for your game \$\endgroup\$
    – Zibelas
    Dec 29, 2023 at 20:53
  • \$\begingroup\$ @Basic Combining the PNG byte array and game data and saving the result as a PNG file is one way to achieve this.I’m wondering if there are any other better methods \$\endgroup\$
    – fatdrogen
    Dec 29, 2023 at 23:22
  • 2
    \$\begingroup\$ Better methods than what at achieving what? \$\endgroup\$
    – Basic
    Dec 30, 2023 at 0:57

1 Answer 1

0
\$\begingroup\$

There is the code you can modify outPng as you wish (Texture2D have lot of useful methods) and then save it as png file anywhere you want:

Texture2D outPng;
var toPng = outPng.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/filename"+ ".png", toPng);
\$\endgroup\$
1
  • \$\begingroup\$ This is not answering the question in the regard on how to convert save data to the texture in the first place. \$\endgroup\$
    – Zibelas
    Dec 30, 2023 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .