/// <summary> /// Metodo para añadir una foto al formulario /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public async void Adjuntar_Click_1(object sender, RoutedEventArgs e) { PersonPicture personPicture = (PersonPicture)sender; var fileOpenPicker = new FileOpenPicker(); fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fileOpenPicker.FileTypeFilter.Add(".png"); fileOpenPicker.FileTypeFilter.Add(".jpg"); fileOpenPicker.FileTypeFilter.Add(".jpeg"); fileOpenPicker.FileTypeFilter.Add(".bmp"); fileOpenPicker.FileTypeFilter.Add(".jfif"); var storageFile = await fileOpenPicker.PickSingleFileAsync(); if (storageFile != null) { // Ensure the stream is disposed once the image is loaded using (IRandomAccessStream fileStream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read)) { // Set the image source to the selected bitmap BitmapImage bitmapImage = new BitmapImage(); await bitmapImage.SetSourceAsync(fileStream); personPicture.ProfilePicture = bitmapImage; clsConversorImagen conversor = new clsConversorImagen(); Task <byte[]> taskImage = conversor.convertirAByte(storageFile); byte[] foto = await taskImage; personaSeleccionada.foto = foto; } } }
/// <summary> /// Este metodo llama al metodo que convierte un array de bytes a bitmap.(Es necesario por el await) /// </summary> public async void convertirBitmap() { clsConversorImagen conversor = new clsConversorImagen(); if (personaSeleccionada.foto != null) { Task <BitmapImage> taskImage = conversor.convertirABitmap(personaSeleccionada.foto); _imagen = await taskImage; NotifyPropertyChanged("imagen"); } }