- Home /
EncodeToPNG Creates a Question Mark 8x8 Texture C#
Hey people! I was trying to export a texture that I made to png, but all I got was a question mark as the actual image. I do not get what I am doing wrong, and I have found nothing on the internet about this issue. Anyway, here is my code.
Texture2D tex = new Texture2D(1, 1);
tex.LoadImage(Encoding.ASCII.GetBytes(File.ReadAllText(n)));
File.WriteAllBytes("stuff.png", tex.EncodeToPNG());
The variable n refers to a png image path, which IS existing. Also, this code probably looks a bit weird because I am importing and exporting the same png image, but this is just some code that I am trying to get working.
Answer by saschandroid · Dec 14, 2015 at 08:08 AM
What are you trying to do with Encoding.ASCII.GetBytes(File.ReadAllText(n)) ? Have you tried tex.LoadImage(File.ReadAllBytes(n)); ?
Right, i converted the comment into an answer ^^.
Text encoding makes no sense when dealing with binary data. Ever tried opening a png or exe file in notepad and save it again? :D Just as a tip: create a backup first, you'll need it.
Your answer