Getting red question mark when using Texture2D.LoadImage!
So yesterday i wrote some code to open and save images from unity. I save them as byte[] in my database. But the problem comes when i try to load them. I'm using Texture2D.LoadImage(byte[],bool) for that job but it doesn't seem to work. I'm getting a red question mark on my image when i try to load something. Every answer will be appreciated. Here's the code:
public void LoadFile()
{
IDbCommand comLA = con.CreateCommand();
comLA.CommandText = "SELECT * from pics";
IDataReader reader;
reader = comLA.ExecuteReader();
string bytes = "";
while (reader.Read())
{
bytes = reader.GetString(0);
}
reader.Close();
imageBytes = StringToByteArray(bytes);
ByteArrayToImage();
}
public void ByteArrayToImage()
{
Texture2D imageTex = new Texture2D(1, 1);
imageTex.LoadImage(imageBytes, true);
Sprite sprite = Sprite.Create(imageTex, new Rect(0.0f, 0.0f, imageTex.width, imageTex.height), new Vector2(0.5f, 0.5f), 100.0f);
i.sprite = sprite;
}
public byte[] StringToByteArray(string data)
{
var bytes = System.Text.Encoding.Unicode.GetBytes(data);
return bytes;
}
Answer by unity_jS1CcpCTTdmJEw · Aug 18, 2020 at 12:18 PM
Same problem here, did you find any solution?
Your answer

Follow this Question
Related Questions
Using transparent images in Unity 1 Answer
Change texture from file on runtime (Windows / macOS) 0 Answers
Taking a Screenshot and then displaying the Screenshot in game 0 Answers
How can I set an Image (PNG) from a URL to be the material of a sphere ?? 0 Answers
Get a single texture from multiply one (from atlas) 1 Answer