- Home /
Question by
Kiloblargh · Oct 05, 2012 at 04:18 PM ·
filedatamappngmultidimensional array
How do I convert an 8-bit PNG file to a Color[x,y] and vice versa?
Title says it all... But I haven't done anything yet with data reading / writing / parsing beyond PlayerPrefs, so I don't know how hard that is to do. Or even if converting a PNG file to a Color[x,y] is even the right thing to be trying to do. I am trying to make a simple map system where each pixel spawns a tile prefab.
Comment
Best Answer
Answer by Eric5h5 · Oct 05, 2012 at 04:26 PM
You can use WWW.texture followed by GetPixels32. That will result in a Color32[x*y] array rather than a 2D array, but it doesn't really matter. (You would prefer to use Color32 over Color in most cases.)
As for the vice versa part, use Texture2D.EncodeToPNG followed by System.IO.File.WriteAllBytes.