What happens is that I have an image captured from a PC folder
//Capturar imagen
//https://docs.microsoft.com/es-es/windows/uwp/files/quickstart-using-file-and-folder-pickers
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file == null)
return;
After capturing it I show it in one <Image/>
by means of Binding to the ViewModel from the XAML
<Image Source="{Binding CurrentImage, Mode=TwoWay}" Width="150" Height="150" HorizontalAlignment="Left"/>
and this is the code of the View Model, I create the property to which I am going to Bind:
public ImageSource CurrentImage { get { return currentImage; } set { Set(ref currentImage, value); } }
private ImageSource currentImage;
and inside the method it goes like this:
//Mostrar en <Image/>
//https://stackoverflow.com/questions/34214553/binding-image-source-to-page
var bitmap = new BitmapImage();
await bitmap.SetSourceAsync(await file.OpenReadAsync());
this.CurrentImage = bitmap;
Now what I need is to Serialize it in bytes to save it in the database and I have not been able to
I saw this video and it doesn't work for me, the Image property generates an error, it doesn't appear, I don't know if I have to import a library: https://www.youtube.com/watch?v=NUTdln165aw
I also looked at this Blog and it doesn't work for me, it won't let me import System.Drawing.Image
: https://stackoverflow.com/questions/3801275/how-to-convert-image-to-byte-array
and I don't know how I could do the serialization in UWP with C#
Already solved. the code to pass a BitmapImage to Bytes in UWP is this, leave the other one and do this:
and what I do is send
imageBytes
to the SQLand to bring it back we do this, taking into account that we already have the Binding of the
<image/>
in XAML (although above I explain how to do it I repeat it):And ready the chicken, the truth is not easy to find UWP documentation but there you do what you can