I have a SQLite database full of BLOB fields containing .PNG images that I’m trying to load in Unity with C#.
Here’s how I’m getting the byte[ ] from the DB:
reader.GetBytes(index++, 0, imageByteArray, 0, imageByteArray.Length);```
Here's my LoadImage() call:
```var texture = new Texture2D(2, 2);
texture.LoadImage(imageByteArray);```
I have looked at the byte[ ] data in the DB, in the VS debugger, saved as a file, and imported into Unity. It's the same bytes in each location, and it's a valid 32 bit .PNG like Unity expects.
Anyone know why this call might fail? The texture just gets defaulted to an 8x8 red question mark.
There are several PNG standards in the air. Maybe this particular format isn’t supported by Unity.
I can’t help you any other way than suggest you to make sure that these PNG files do really work in Unity before trying to pull them from the DB.
Maybe I’m distracting you from the real source of the problem, but I’m thinking it’s worth checking.
Do you mean if you put your original image in your database, then extract it with your code above, then write that byte array to disk as a separate file, those two files are identical?
That is the first test I would try… I bet there will be something different between the two files. You can use something like openssl sha1
to check the files are truly identical hash-wise.
1 Like