How to convert .png to texture from file path?

I am trying to create a texture from .png file. I have the path to the file in a string. I just don’t know how to turn it into a texture.

string theFilePath;

Texture2D tex = new Texture2D(2, 2);

// This is where I am stuck as the function takes an byte. And I do not know how to get that from a png filepath

// tex.LoadImage(imageAsset.bytes);

You need to use C#'s File class to read in the image from disk. When you read it, you have the option to read it in as a series of bytes. These are the bytes that you can feed to Unity’s runtime image importer, which is what LoadImage does.

Here’s the script reference to get you started: https://msdn.microsoft.com/en-us/library/system.io.file(v=vs.110).aspx

There are a number of tutorials on reading in the bytes of a file from disk.

Good luck!