lundi 21 septembre 2015

How do I read out a blob back to byte array from sqlite?

I have an OpenFileDialog which allows users to select a single .png image. I store this into a property as such:

public byte[] HeroesDBThumbnailImage ...
...
if(OFD.ShowDialog() == true)
{
    HeroesDBThumbnailImage = File.ReadAllBytes(OFD.FileName);
    HeroesDBThumbnailPath = OFD.SafeFileName;
}

Once the value is set there, I am Inserting the entry to the DB as follows:

query = ....blahblah...
query += "'" Convert.ToBase64String(HeroesDBThumbnailImage) + "','" + Convert.ToBase64String(HeroesDBFeaturedThumbnailImage) + "'); ";

It appears to insert data to the DB, so I was happy.

Then, I read it back as so:

new Hero(
...
HThumbnailImage: (byte[])Row["ThumbnailImage"]
) ...

in the XAML, I have an image, for testing, which I bound to the original byte array. As soona s the user selects an image from the file selector, the image source, bound to that property, displays that image.

However, when I read the data back into the other property, another test image, bound to that byte array does not display anything. All bindings are correct, and I tried to debug at runtime and the byte array is being read back out, however it appears to be coming back a different size from the original... Original was 899 bytes, once read back out from DB it appears to be about 940 ish...

The field in SQLite DB is BLOB by the way.

Thanks

Aucun commentaire:

Enregistrer un commentaire