Is that I have a serialized image in an array of Bytes in C # - UWP, here the post: How to serialize an image (bitmap) in bytes [] C # UWP?
but now I have to save it in a Data Database in SQL and I do not know what field to use for that.
thanks
Is that I have a serialized image in an array of Bytes in C # - UWP, here the post: How to serialize an image (bitmap) in bytes [] C # UWP?
but now I have to save it in a Data Database in SQL and I do not know what field to use for that.
thanks
I do not know why they rate me badly, but for all the gritty this is the answer:
What you need to do is create a varbinary
field in the database table.
Then the image that is in bytes is converted to string64 and saved in the DB.
string base64 = Convert.ToBase64String(imageByte);
And when it has to be brought back, it is deviated from string64 to Bytes []
byte[] bytesConvertBack = Convert.FromBase64String(base64);
To understand the fields, check the question where I do the serialization of Image to Bytes in UWP. How to serialize a image (bitmap) in bytes [] C # UWP?
thanks for nothing
Try this, suppose you want to load an image: (img is your file) I also clarify that you are trajandpo with C # MVC EntityFramework
This is the way:
var binarioImagen = new BinaryReader(img.InputStream);
Byte[] imagenFoto = binarioImagen.ReadBytes(img.ContentLength);
The in your Class must declare a property as an example byte array like this:
public class Fotos
{
int Id { get; set; }
string nombre { get; set; }
public byte[] Foto { get; set; }
}
you can use the dbContext to save the SQLServer database