private async void ButtonCamera_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();
            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(600, 600);

            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo != null)
            {
                BitmapImage bmp = new BitmapImage();
                IRandomAccessStream stream = await photo.
                                                   OpenAsync(FileAccessMode.Read);
                bmp.SetSource(stream);
                BBQImage.Source = bmp;

                FileSavePicker savePicker = new FileSavePicker();
                savePicker.FileTypeChoices.Add
                                      ("jpeg image", new List<string>() { ".jpeg" });

                savePicker.SuggestedFileName = "New picture";

                StorageFile savedFile = await savePicker.PickSaveFileAsync();

                (this.DataContext as BBQRecipeViewModel).imageSource = savedFile.Path;

                if (savedFile != null)
                {
                    await photo.MoveAndReplaceAsync(savedFile);
                }
            }
        }
        private async void OnCapturePhotoButtonClick(object sender, RoutedEventArgs e)
        {
            var file = await TestedControl.CapturePhotoToStorageFileAsync(ApplicationData.Current.TemporaryFolder);
            var bi = new BitmapImage();

            IRandomAccessStreamWithContentType stream;

            try
            {
                stream = await TryCatchRetry.RunWithDelayAsync<Exception, IRandomAccessStreamWithContentType>(
                    file.OpenReadAsync(),
                    TimeSpan.FromSeconds(0.5),
                    10,
                    true);
            }
            catch (Exception ex)
            {
                // Seems like a bug with WinRT not closing the file sometimes that writes the photo to.
#pragma warning disable 4014
                new MessageDialog(ex.Message, "Error").ShowAsync();
#pragma warning restore 4014

                return;
            }

            bi.SetSource(stream);
            PhotoImage.Source = bi;
            CapturedVideoElement.Visibility = Visibility.Collapsed;
            PhotoImage.Visibility = Visibility.Visible;
        }
Example #3
0
        /// <summary>
        ///  サムネイル画像を取得しプロパティ変更通知を行う.
        /// </summary>
        private async void GetThumbnailAsync()
        {
            if (this.DeviceItem == null)
            {
                return;
            }
            if (this.DeviceItem.Data.Information == null)
            {
                return;
            }

            var thumbnail = await this.DeviceItem.Data.Information.First().GetThumbnailAsync();

            if (thumbnail == null)
            {
                return;
            }

            this.m_deviceThumbnail = thumbnail;

            var bmpImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            bmpImage.SetSource(thumbnail);

            this.thumbnailBitmapImage = bmpImage;
            OnPropertyChanged("ThumbnailBitmapImage");
        }
        public async void OdabirSlikeAsync(object parameter)
        {
            var IzbornikSlike = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
            };

            IzbornikSlike.FileTypeFilter.Add(".jpg");
            IzbornikSlike.FileTypeFilter.Add(".jpeg");
            IzbornikSlike.FileTypeFilter.Add(".png");
            Windows.Storage.StorageFile Slika = await IzbornikSlike.PickSingleFileAsync();

            if (Slika == null)
            {
                MessageDialog greska = new MessageDialog("Greška pri odabiru slike!");
                greska.ShowAsync();
                return;
            }
            else
            {
                using (Windows.Storage.Streams.IRandomAccessStream fileStream = await Slika.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    Windows.UI.Xaml.Media.Imaging.BitmapImage SlikaBitMapa = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    SlikaBitMapa.SetSource(fileStream);
                    PathSlike = Convert.ToString(fileStream);
                }
            }
        }
Example #5
0
        private async void SelectPictureButton_Click(object sender, RoutedEventArgs e)
        {
            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)
            {
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    Background.Source = bitmapImage;
                }
            }
            else
            {
                this.textBlock.Text = "Operation cancelled.";
            }
        }
Example #6
0
 public static async Task<BitmapImage> getImageSource(string imageName)
 {
     if (string.IsNullOrEmpty(imageName))
     {
         return null;
     }
     try
     {
         StorageFile sourcePhoto = await KnownFolders.CameraRoll.GetFileAsync(imageName);
         if (sourcePhoto != null)
         {
             using (var fileStream = await sourcePhoto.GetThumbnailAsync(ThumbnailMode.PicturesView))
             {
                 sourcePhoto = null;
                 var img = new BitmapImage();
                 img.SetSource(fileStream);
                 return img;
             }
         }
     }
     catch (Exception e)
     {
     }
     return null;
 }
Example #7
0
        private async void GetAllVideos(StorageFolder KnownFolders, QueryOptions QueryOptions)
        {
            StorageFileQueryResult query = KnownFolders.CreateFileQueryWithOptions(QueryOptions);
            IReadOnlyList<StorageFile> folderList = await query.GetFilesAsync();

            // Get all the videos in the folder past in parameter
            int id = 0;
            foreach (StorageFile file in folderList)
            {
                using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.VideosView, 200, ThumbnailOptions.UseCurrentScale))
                {
                    // Get video's properties
                    VideoProperties videoProperties = await file.Properties.GetVideoPropertiesAsync();

                    BitmapImage VideoCover = new BitmapImage();
                    VideoCover.SetSource(thumbnail);

                    Video video = new Video();
                    video.Id = id;
                    video.Name = file.Name;
                    video.DateCreated = file.DateCreated.UtcDateTime;
                    video.FileType = file.FileType;
                    video.VideoPath = file.Path;
                    video.Duration = videoProperties.Duration;
                    video.VideoFile = file;
                    video.VideoCover = VideoCover;

                    // Add the video to the ObservableCollection
                    Videos.Add(video);
                    id++;
                }
            }
        }
Example #8
0
        private async void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker filepicker = new Windows.Storage.Pickers.FileOpenPicker();
            filepicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            filepicker.FileTypeFilter.Add(".jpg");
            filepicker.FileTypeFilter.Add(".png");
            filepicker.FileTypeFilter.Add(".bmp");
            filepicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            Windows.Storage.StorageFile imageFile = await filepicker.PickSingleFileAsync();

            if (imageFile != null)
            {
                Windows.UI.Xaml.Media.Imaging.BitmapImage   bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                Windows.Storage.Streams.IRandomAccessStream stream = await imageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                Image newImage = new Image();
                bitmap.SetSource(stream);
                newImage.Source = bitmap;
                //newImage.Height = 250;
                newImage.Stretch          = Stretch.UniformToFill;
                newImage.ManipulationMode = ManipulationModes.All;

                this.MyCanvas.Children.Add(newImage);
            }
        }
Example #9
0
 public async Task<Windows.UI.Xaml.Media.Imaging.BitmapImage> GetBitmapAsync()
 {
     var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
     stream.Seek(0);
     image.SetSource(stream);
     return image;
 }
Example #10
0
    private void PlatformSetup()
    {
      PlatformTest.ResultsDirectory = "TestResults";
      PlatformTest.Platform = Platforms.Current;

      PlatformTest.OpenStream = path => new FileMemoryStream {Path = path};
      PlatformTest.CloseStream = async (stream, name) =>
      {
        //await UploadToLocalhost(name, stream, client);

        using (var memStream =
          stream.AsRandomAccessStream())
        {
          var bitmapImage = new BitmapImage();
          memStream.Seek(0);
          bitmapImage.SetSource(memStream);

          SampleImages.Add(new SampleImage
          {
            Name = name,
            ImageSource = bitmapImage
          });
        }
      };
    }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                parameter = e.Parameter as FromExpositionToDiaporama;
                ListPhoto = new ObservableCollection<Pages.PhotoDataStructure>();
                listSmallPhoto = parameter.ListPhoto;
                foreach (var row in listSmallPhoto)
                {
                    try
                    {
                        StorageFile file = await Windows.Storage.StorageFile.GetFileFromPathAsync(row.PhotoData.ImagePath);
                        StorageItemThumbnail fileThumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, (uint)Constants.ScreenHeight, ThumbnailOptions.UseCurrentScale);
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.SetSource(fileThumbnail);

                        ListPhoto.Add(new Pages.PhotoDataStructure()
                        {
                            PhotoData = row.PhotoData,
                            Image = bitmapImage
                        });
                    }
                    catch
                    { }
                }
                flipView.ItemsSource = ListPhoto;
                if (listSmallPhoto.Count > 0)
                    pageTitle.Text = parameter.albumName;
                dispatcherTimer2 = new DispatcherTimer();
                dispatcherTimer2.Tick += dispatcherTimer2_Tick;
                dispatcherTimer2.Interval = new TimeSpan(0, 0, 0, 0, 2);
                dispatcherTimer2.Start();
            }
            catch (Exception excep) { Constants.ShowErrorDialog(excep, "PhotoPlayPage - OnNavigatedTo"); }
        }
Example #12
0
        /// <summary>
        /// 他のアプリケーションがこのアプリケーションを介してコンテンツの共有を求めた場合に呼び出されます。
        /// </summary>
        /// <param name="args">Windows と連携して処理するために使用されるアクティベーション データ。</param>
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this.currentModel = BookmarkerModel.GetDefault();
            await this.currentModel.LoadAsync();

            this._shareOperation = args.ShareOperation;

            // ビュー モデルを使用して、共有されるコンテンツのメタデータを通信します
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage = new BitmapImage();
            this.DefaultViewModel["Title"] = shareProperties.Title;
            this.DefaultViewModel["Description"] = shareProperties.Description;
            this.DefaultViewModel["Image"] = thumbnailImage;
            this.DefaultViewModel["Sharing"] = false;
            this.DefaultViewModel["ShowImage"] = false;
            this.DefaultViewModel["Comment"] = String.Empty;
            this.DefaultViewModel["SupportsComment"] = true;

            this.addBookmarkView.Title = shareProperties.Title;
            this.addBookmarkView.Uri = (await this._shareOperation.Data.GetUriAsync()).ToString();

            Window.Current.Content = this;
            Window.Current.Activate();

            // 共有されるコンテンツの縮小版イメージをバックグラウンドで更新します
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();
                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
Example #13
0
 public async static Task<BitmapImage> GetImageAsync(StorageFile storageFile)
 {
     BitmapImage bitmapImage = new BitmapImage();
     FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read);
     bitmapImage.SetSource(stream);
     return bitmapImage;
 }
        public async Task ShareAsync(ShareOperation shareOperation)
        {
            _shareOperation = shareOperation;
            shareOperation.ReportStarted();
            var dataPackageView = shareOperation.Data;

            RequestTitle = shareOperation.Data.Properties.Title;
            RequestDescription = shareOperation.Data.Properties.Description;

            try
            {
                if ( dataPackageView.IsTextMessage() )
                {
                    IsTextRequest = true;
                    TextShareValue = await dataPackageView.GetTextAsync();
                }
                else if (dataPackageView.IsUrlMessage())
                {
                    IsUrlRequest = true;
                    var foundUri = await dataPackageView.GetUriAsync();

                    UrlShareValue = foundUri.AbsoluteUri;
                }
                else if (dataPackageView.IsStorageItemsMessage())
                {
                    IsStorageRequest = true;
                    var storageItems = await dataPackageView.GetStorageItemsAsync();
                    if ( storageItems.Any())
                    {
                        var storageItem = storageItems.First();
                        if ( storageItem.IsOfType(StorageItemTypes.File))
                        {
                            StorageFileName = storageItem.Name;
                            var thumbNail = dataPackageView.Properties.Thumbnail;
                            var thumbnailStream = await thumbNail.OpenReadAsync();

                            ImageShareValue = new BitmapImage();
                            ImageShareValue.SetSource(thumbnailStream);
                        }
                    }
                }
                else if (dataPackageView.IsImageMessage())
                {
                    IsImageRequest = true;
                    var imageRecieved = await dataPackageView.GetBitmapAsync();
                    var imageStream = await imageRecieved.OpenReadAsync();

                    ImageShareValue = new BitmapImage();
                    ImageShareValue.SetSource(imageStream);
                }
            }
            catch (Exception e)
            {
                shareOperation.ReportError(e.Message);               
                RequestDescription = e.Message;
            }
            

            shareOperation.ReportDataRetrieved();
        }
        private async void BrowseButton_Click(object sender, RoutedEventArgs e)
        {

            //Upload picture 
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");

            StorageFile file = await openPicker.PickSingleFileAsync();
            var bitmapImage = new BitmapImage();

            var stream = await file.OpenAsync(FileAccessMode.Read);
            bitmapImage.SetSource(stream);
           
            if (file != null)
            {
                FacePhoto.Source = bitmapImage;                
                scale = FacePhoto.Width / bitmapImage.PixelWidth;
            }
            else
            {
                Debug.WriteLine("Operation cancelled.");
            }

            // Remove any existing rectangles from previous events 
            FacesCanvas.Children.Clear();

            //DetectFaces
            var s = await file.OpenAsync(FileAccessMode.Read);
            List<MyFaceModel> faces = await DetectFaces(s.AsStream());
            DrawFaces(faces);
        }
        private async Task<BitmapImage> GetImageForId(string id)
        {

            var contactStore = await ContactManager.RequestStoreAsync();
            var contact = await contactStore.GetContactAsync(id);

            if (contact.Thumbnail == null)
            {
                BitmapImage image = new BitmapImage();
                image.DecodePixelHeight = 100;
                image.DecodePixelWidth = 100;

                return image;
            }

            using (var stream = await contact.Thumbnail.OpenReadAsync())
            {

                BitmapImage image = new BitmapImage();
                image.DecodePixelHeight = 100;
                image.DecodePixelWidth = 100;

                image.SetSource(stream);

                return image;
            }
        }
Example #17
0
        public static async Task<List<LocationData>> GetPhotoInDevice()
        {
            List<LocationData> mapPhotoIcons = new List<LocationData>();
            IReadOnlyList<StorageFile> photos = await KnownFolders.CameraRoll.GetFilesAsync();
            for (int i = 0; i < photos.Count; i++)
            {

                Geopoint geopoint = await GeotagHelper.GetGeotagAsync(photos[i]);
                if (geopoint != null)
                {
                    //should use Thumbnail to reduce the size of images, otherwise low-end device will crashes
                    var fileStream = await photos[i].GetThumbnailAsync(ThumbnailMode.PicturesView);
                    var img = new BitmapImage();
                    img.SetSource(fileStream);


                    mapPhotoIcons.Add(new LocationData
                    {
                        Position = geopoint.Position,
                        DateCreated = photos[i].DateCreated,
                        ImageSource = img
                    });
                }
            }
            var retMapPhotos = mapPhotoIcons.OrderBy(x => x.DateCreated).ToList();

            return retMapPhotos;
        }
 private async Task<BitmapImage> LoadImage(StorageFile file)
 {
     var image  = new BitmapImage();
     FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);
     image.SetSource(stream);
     return image;
 }
Example #19
0
        private async Task DisplayStorageFileAsync(StorageFile storageFile)
        {
            var bitmapImage = new BitmapImage();
            bitmapImage.SetSource(await _storageFile.OpenAsync(FileAccessMode.Read));

            ImagePhoto.Source = bitmapImage;
        }
Example #20
0
        public async void LoadPicture(FlickrNet.Photo photo)
        {
            //imgMain.Source = new Uri(photo.OwnerName);

            try
            {
                var folder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync("ModernCSApp");
                var file = await folder.GetFileAsync(photo.PhotoId + "_" + photo.Secret + ".jpg");

                using (var stream = await file.OpenReadAsync())
                {
                    BitmapImage bi = new BitmapImage();
                    bi.SetSource(stream);
                    imgMain.Source = bi;


                    //if (RenderingService.MagicRenderer != null && RenderingService.MagicRenderer is ISpriteRenderer)
                    //{
                    //    var gt = Window.Current.Content.TransformToVisual(imgMain);
                    //    var p = gt.TransformPoint(new Point(0, 0));
                    //    ((ISpriteRenderer)RenderingService.MagicRenderer).AddSprite(p.X, p.Y, 0, 1);
                    //}
                }


                //imgMain.Source = bi;
                if (ChangeViewState != null) ChangeViewState("Normal", null);
            }
            catch { 
            
            }
        }
Example #21
0
        public async Task LoadPicture(Favourite photo)
        {
            
            try
            {

                layoutRoot.DataContext = photo;

                var folder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync("ModernCSApp");
                var file = await folder.GetFileAsync(photo.AggregateId.Replace("-","") + ".jpg");

                using (var stream = await file.OpenReadAsync())
                {
                    BitmapImage bi = new BitmapImage();
                    bi.SetSource(stream);
                    imgMain.Source = bi;

                }

                grdPhotoQuickDetails.Visibility = Windows.UI.Xaml.Visibility.Visible;
                
                if (photo.MediaTitle != string.Empty) grdPhotoQuickDetailsTop.Visibility = Windows.UI.Xaml.Visibility.Visible;
                else grdPhotoQuickDetailsTop.Visibility = Visibility.Collapsed;

                //imgMain.Source = bi;
                if (ChangeViewState != null) ChangeViewState("Normal", null);
            }
            catch
            {

            }
        }
Example #22
0
        /// <summary>
        /// Invoked when another application wants to share content through this application.
        /// </summary>
        /// <param name="args">Activation data used to coordinate the process with Windows.</param>
        public async void Activate(ShareTargetActivatedEventArgs args)
        {
            this._shareOperation = args.ShareOperation;
            

            // Communicate metadata about the shared content through the view model
            var shareProperties = this._shareOperation.Data.Properties;
            var thumbnailImage = new BitmapImage();
            this.DefaultViewModel["Title"] = shareProperties.Title;
            this.DefaultViewModel["Description"] = shareProperties.Description;
            this.DefaultViewModel["Image"] = thumbnailImage;
            this.DefaultViewModel["Sharing"] = false;
            this.DefaultViewModel["ShowImage"] = false;
            this.DefaultViewModel["Comment"] = String.Empty;
            this.DefaultViewModel["SupportsComment"] = true;
            Window.Current.Content = this;
            Window.Current.Activate();

            Detector dt = new Detector(_shareOperation.Data);
            dt.Detect();
            this.DataContext = dt.Detected;

            // Update the shared content's thumbnail image in the background
            if (shareProperties.Thumbnail != null)
            {
                var stream = await shareProperties.Thumbnail.OpenReadAsync();
                thumbnailImage.SetSource(stream);
                this.DefaultViewModel["ShowImage"] = true;
            }
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value != null && value is byte[])
            {

                //WriteableBitmap bitmap = new WriteableBitmap(100, 100);

                //System.IO.Stream bitmapStream = null;
                //bitmapStream = bitmap.PixelBuffer.AsStream();
                //bitmapStream.Position = 0;
                //bitmapStream.Write(value as byte[], 0, (value as byte[]).Length);

                //bitmapStream.Flush();

                InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
                DataWriter writer = new DataWriter(randomAccessStream.GetOutputStreamAt(0));
                writer.WriteBytes(value as byte[]);
                var x = writer.StoreAsync().AsTask().Result;
                BitmapImage image = new BitmapImage();
                image.SetSource(randomAccessStream);

                return image;
            }

            return null;
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            BitmapImage image = null;

            if (value != null)
            {
                if (value.GetType() != typeof(FileRandomAccessStream))
                {
                    throw new ArgumentException("Expected a StorageItemThumbnail as binding input.");
                }
                if (targetType != typeof(ImageSource))
                {
                    throw new ArgumentException("Expected ImageSource as binding output.");
                }

                if ((FileRandomAccessStream)value == null)
                {
                    return image;
                }

                image = new BitmapImage();

                using (var thumbNailClonedStream = ((FileRandomAccessStream)value).CloneStream())
                    image.SetSource(thumbNailClonedStream);
            }

            return (image);
        }
        private async void Add_image(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fp = new FileOpenPicker();

            // Adding filters for the file type to access.
            fp.FileTypeFilter.Add(".jpeg");
            fp.FileTypeFilter.Add(".png");
            fp.FileTypeFilter.Add(".bmp");
            fp.FileTypeFilter.Add(".jpg");

            // Using PickSingleFileAsync() will return a storage file which can be saved into an object of storage file class.

            StorageFile sf = await fp.PickSingleFileAsync();

            // Adding bitmap image object to store the stream provided by the object of StorageFile defined above.
            BitmapImage bmp = new BitmapImage();

            // Reading file as a stream and saving it in an object of IRandomAccess.
            IRandomAccessStream stream = await sf.OpenAsync(FileAccessMode.Read);

            // Adding stream as source of the bitmap image object defined above
            bmp.SetSource(stream);

            // Adding bmp as the source of the image in the XAML file of the document.
            image.Source = bmp;
        }
Example #26
0
        public async Task LoadImage()
        {
            if (ImageFileName.Contains("ms-appx:Assets"))
            {
                BitmapImage bitmapImage = new BitmapImage(new Uri(ImageFileName, UriKind.RelativeOrAbsolute));
                ImageBrush  brush       = new ImageBrush();
                brush.AlignmentX      = AlignmentX.Left;
                brush.AlignmentY      = AlignmentY.Top;
                brush.Stretch         = Stretch.UniformToFill;
                _picBrush.ImageSource = bitmapImage;
                return;
            }

            var folder = await StaticHelpers.GetSaveFolder();

            var file = await folder.GetFileAsync(ImageFileName);

            using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                _picBrush.ImageSource = bitmapImage;
            }
        }
Example #27
0
 public static async Task<BitmapImage> TileToImage(byte[] tile)
 {
     var image = await ByteArrayToRandomAccessStream(tile);
     var bitmapImage = new BitmapImage();
     bitmapImage.SetSource(image);
     return bitmapImage;
 }
        private async void clickbtn_Click(object sender, RoutedEventArgs e)
        {
            FolderPicker fp = new FolderPicker();
            fp.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fp.ViewMode = PickerViewMode.Thumbnail;
            fp.FileTypeFilter.Add(".jpg");
            fp.FileTypeFilter.Add(".png");
            fp.FileTypeFilter.Add(".jpeg");
            var file = await fp.PickSingleFolderAsync();
            fl = await file.GetFilesAsync();
            if (file != null)
            {
                StorageFile sf = fl[0];
                foreach (StorageFile images in fl)
                {
                    IRandomAccessStream str = await images.OpenAsync(FileAccessMode.Read);
                    BitmapImage bitmapimage = new BitmapImage();
                    bitmapimage.SetSource(str);

                    fp1.Items.Add(bitmapimage);
                 

                 
                }
        
            }

        }
Example #29
0
		private async void Button_Click_2(object sender, RoutedEventArgs e)
		{
			var mem = new InMemoryRandomAccessStream();
			var enc = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, mem);

			int width = 140, height = 140;
			int plane = 4;
			byte[] data = new byte[width * height * plane];
			int offset = 0;
			for (int y = 0; y < width; y++)
			{
				for (int x = 0; x < height; x++)
				{
					data[offset + 0] = 0xFF; // R
					data[offset + 1] = 0x00; // G
					data[offset + 2] = 0x00; // B
					data[offset + 3] = 0xFF; // Alpha
					offset += 4;
				}
			}
			enc.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
				(uint)width, (uint)height, 96, 96, data);
			await enc.FlushAsync();

			BitmapImage bmp = new BitmapImage();
			bmp.SetSource(mem);
			image1.Source = bmp;
		}
        private async void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                string name = file.Path.ToString();
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    /*Img.Source = new BitmapImage(new Uri(name, UriKind.Relative));*/
                    bitmapImage.SetSource(fileStream);
                    Img.Source = bitmapImage;
                }
            }
        }
 private void getStream_LockScreen_Click(object sender, RoutedEventArgs e)
 {
     IRandomAccessStream randomAccessStream = LockScreen.GetImageStream();
     BitmapImage image = new BitmapImage();
     image.SetSource(randomAccessStream);
     imageview.Source = image;
 }
        public async Task<string> GetPictureFromGalleryAsync()
		{
            FileOpenPicker openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                var stream = await file.OpenAsync(FileAccessMode.Read);
                BitmapImage image = new BitmapImage();
                image.SetSource(stream);

                var path = Path.Combine(StorageService.ImagePath);
                _url = String.Format("Image_{0}.{1}", Guid.NewGuid(), file.FileType);
                var folder = await StorageFolder.GetFolderFromPathAsync(path);

                //TODO rajouter le code pour le redimensionnement de l'image

                await file.CopyAsync(folder, _url);
                return string.Format("{0}\\{1}", path, _url);
            }

            return "";
		}
 public static async Task LoadImageToMemory(AlbumItem item)
 {
     /*
     Normally, We would need more tight calls to try and make sure that the file
     exists in our database. However, since this is on the UI thread, we can't do that.
     Since binding images directly through XAML leads to blocked files when we
     need to delete them, we have to load them up manually. This should be enough
     of a check, for now, to make sure images load correctly.
     */
     bool fileExists = item.IsPictureLoaded;
     try
     {
         if (fileExists)
         {
             var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(item.AlbumCoverFullUri));
             using (var stream = await file.OpenAsync(FileAccessMode.Read))
             {
                 await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                 {
                     var image = new BitmapImage();
                     image.SetSource(stream);
                     item.AlbumImage = image;
                 });
             }
         }
     }
     catch (Exception)
     {
         LogHelper.Log("Error getting album picture : " + item.Name);
     }
     if (!fileExists)
     {
         await MusicLibraryManagement.FetchAlbumCoverOrWaitAsync(item);
     }
 }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value != null)
            {

                byte[] bytes = (byte[])value;
                BitmapImage myBitmapImage = new BitmapImage();
                if (bytes.Count() > 0)
                {


                    InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
                    DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0));

                    writer.WriteBytes(bytes);
                    writer.StoreAsync().GetResults();
                    myBitmapImage.SetSource(stream);
                }
                else
                {
                    myBitmapImage.UriSource = new Uri("ms-appx:///Assets/firstBackgroundImage.jpg");
                }

                return myBitmapImage;
            }
            else
            {
                return new BitmapImage();
            }
        }
        private async void GetSmallImageButton_Click(object sender, RoutedEventArgs e)
        {
            // The small picture returned by GetAccountPicture() is 96x96 pixels in size.
            StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile;
            if (image != null)
            {
                rootPage.NotifyUser("SmallImage path = " + image.Path, NotifyType.StatusMessage);

                try
                {
                    IRandomAccessStream imageStream = await image.OpenReadAsync();
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(imageStream);
                    smallImage.Source = bitmapImage;

                    smallImage.Visibility = Visibility.Visible;
                    largeImage.Visibility = Visibility.Collapsed;
                    mediaPlayer.Visibility = Visibility.Collapsed;
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Error opening stream: " + ex.ToString(), NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Small Account Picture is not available", NotifyType.StatusMessage);
                mediaPlayer.Visibility = Visibility.Collapsed;
                smallImage.Visibility = Visibility.Collapsed;
                largeImage.Visibility = Visibility.Collapsed;
            }
        }
        private static async void OnFileChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue == null)
            {
                return;
            }

            var behavior = d as FileThumbnailImageSourceBehavior;
            if (behavior?.Parent == null)
            {
                return;
            }

            var thumb =
                await behavior.File.GetThumbnailAsync(ThumbnailMode.SingleItem, 32, ThumbnailOptions.ResizeThumbnail);

            if (thumb == null)
            {
                return;
            }

            var bitmapImage = new BitmapImage();
            bitmapImage.SetSource(thumb.CloneStream());

            behavior.Parent.Source = bitmapImage;
        }
Example #37
0
        public async Task <Windows.UI.Xaml.Media.Imaging.BitmapImage> GetBitmapAsync()
        {
            var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            stream.Seek(0);
            image.SetSource(stream);
            return(image);
        }
Example #38
0
        private async void LoadCoursebg()
        {
            var picpath = (string)localSetting.Values["coursebg"];

            if (picpath.Contains("ms-appx"))
            {
                var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri(picpath));

                course_bg.SetSource(await file.OpenReadAsync());
            }
            else
            {
                var file = await Windows.Storage.StorageFile.GetFileFromPathAsync(picpath);

                course_bg.SetSource(await file.OpenReadAsync());
            }
        }
Example #39
0
        private async void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");

            // Open the file picker.
            Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

            // file is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                displayImage.Source = bitmapImage;

                this.DataContext = file;
            }

            try
            {
                var db     = new SQLite.SQLiteConnection(App.DBPath);
                var emptab = (db.Table <lawyer>().Where(em => em.username == txt1.Text)).Single();

                var targetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(emptab.username + ".jpg");

                if (targetFile != null)
                {
                    //await file.MoveAndReplaceAsync(targetFile);
                    await file.CopyAndReplaceAsync(targetFile);
                }
            }
            catch (Exception ex)
            {
                var var_name = new MessageDialog("Unable to update profile picture\nPlease try after sometime.");
                var_name.Commands.Add(new UICommand("OK"));
                var_name.ShowAsync();
            }

            // await file.CopyAsync(ApplicationData.Current.LocalFolder);
        }
Example #40
0
        Image[,] winCombo = new Image[4, 4];        //winning combination


        //Lets the user choose an image from the local drive. If an image is chosen, a timer is started.
        //Also, this method calls the PlaceImg method to cut and shuffle.
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            loser.Visibility  = Visibility.Collapsed;
            winner.Visibility = Visibility.Collapsed;
            // Set up the file picker.
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");
            Error.Visibility = Visibility.Collapsed;
            // Open the file picker.
            Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

            // 'file' is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                // The 'using' block ensures the stream is disposed
                // after the image is loaded.
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    image1.Source = bitmapImage;
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);

                    PlaceImg(decoder);
                }
                play            = true;
                Timer1          = new Windows.UI.Xaml.DispatcherTimer();
                Timer1.Interval = TimeSpan.FromMilliseconds(1000);
                Timer1.Tick    += Timer1_Tick;
                if (Timer1.IsEnabled)
                {
                    Timer1.Stop();
                }
                Timer1.Start();
                time = GameTime;

                Choose.IsEnabled  = false;
                Capture.IsEnabled = false;
            }
        }
Example #41
0
        private async void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            title.Text   = "";
            details.Text = "";
            date.Date    = DateTime.Now;
            time.Time    = DateTime.Now.TimeOfDay;
            RandomAccessStreamReference img    = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/fruit.jpg"));
            IRandomAccessStream         stream = await img.OpenReadAsync();

            BitmapImage bmp = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            bmp.SetSource(stream);
            pic.Source = bmp;
        }
        /// <summary>
        /// Select_Image_Click allows user to select a an image using filepicker.
        /// Filepath is supposed to start at PicturesLibrary
        /// Image selected is then sent to mediaplayer.postersource on page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Select_Image_Click(object sender, RoutedEventArgs e)
        {
            var ImagePicker = new Windows.Storage.Pickers.FileOpenPicker();

            string[] ImageTypes = new string[] { ".jpg" };            //make a collection of all Pictures you want

            //Add your ImageTypes to the ImageTypeFilter list of ImagePicker.
            foreach (string ImageType in ImageTypes)
            {
                ImagePicker.FileTypeFilter.Add(ImageType);
            }

            //Set picker start location to the Saved Picture library
            ImagePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            ImagePicker.ViewMode = PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            ImagePicker.FileTypeFilter.Clear();
            ImagePicker.FileTypeFilter.Add(".bmp");
            ImagePicker.FileTypeFilter.Add(".png");
            ImagePicker.FileTypeFilter.Add(".jpeg");
            ImagePicker.FileTypeFilter.Add(".jpg");

            //Retrieve file from picker
            StorageFile file = await ImagePicker.PickSingleFileAsync();

            if (file != null)
            {
                // Open a stream for the selected file.
                // The 'using' block ensures the stream is disposed
                // after the image is loaded.
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    System.Diagnostics.Debug.WriteLine("bitmap");
                    //System.Diagnostics.Debug.WriteLine(bitmapImage.UriSource.ToString());
                    System.Diagnostics.Debug.WriteLine("bitmap");
                    _mediaPlayer.PosterSource = bitmapImage;
                    System.Diagnostics.Debug.WriteLine(_mediaPlayer.PosterSource.ToString());
                }
            }
        }
        /// <summary>
        /// If the user needs to choose an existing picture from the Library and use that for face recognition
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");

            // Open the file picker.
            Windows.Storage.StorageFile file =
                await openPicker.PickSingleFileAsync();

            if (file != null)
            {
                pictureName = file.Name;
            }

            // 'file' is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                // The 'using' block ensures the stream is disposed
                // after the image is loaded.
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    FacePhoto.Source = bitmapImage;
                }
            }
        }
        public async void KameraAsync(object parameter)
        {
            CameraCaptureUI KameraUI = new CameraCaptureUI();

            KameraUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

            StorageFile SlikaKamera = await KameraUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (SlikaKamera == null)
            {
                // korisnik prekinuo sliku
                return;
            }
            else
            {
                using (Windows.Storage.Streams.IRandomAccessStream fileStream = await SlikaKamera.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    Windows.UI.Xaml.Media.Imaging.BitmapImage SlikaBitMapa = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    SlikaBitMapa.SetSource(fileStream);
                    PathSlike = Convert.ToString(SlikaBitMapa.UriSource);
                }
            }
        }
Example #45
0
        private async void photo_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.Desktop;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".bmp");
            picker.FileTypeFilter.Add(".gif");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

                Windows.UI.Xaml.Media.Imaging.BitmapImage bmp = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                bmp.SetSource(stream);
                this.image.Source = bmp;
            }
        }
Example #46
0
        private static async Task AddPictureToAlbum(string filePath, string textFileName)
        {
            var         name        = textFileName.Split('.');
            StorageFile storageFile = null;

            try
            {
                storageFile = await StorageFile.GetFileFromPathAsync(filePath);
            }
            catch (UnauthorizedAccessException)
            {
                throw new Exception("Access denied to the folder");
            }

            // Create a bitmap
            var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            using (var stream = await storageFile.OpenAsync(FileAccessMode.Read))
            {
                bitmapImage.SetSource(stream);
            }

            //ObservableCollection<AlbumPic> Album = new ObservableCollection<AlbumPic>();

            // Create Picture object
            var pic = new AlbumHelper();

            pic.Path1        = storageFile.Path;
            pic.ImageSource1 = bitmapImage;
            pic.AlbumName    = name[0];

            //Add picture to album
            Album.Add(pic);

            // Add Album object to the global observable collection
            // Albums.Add(Album);
        }
        //6/7 added
        private async void setImageToMyMediaElement(String imageName)
        {
            // Set the image source to the selected bitmap.
            Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            if (imageName == null || imageName.Trim() == "")
            {
                var defaultSource = new BitmapImage(new Uri("ms-appx:///Assets/earbudsAndSheetMusic.jpg"));
                // bitmapImage.SetSource(defaultSource);
                myMediaPlayerElement.PosterSource = defaultSource;
            }
            else
            {
                var file = await KnownFolders.PicturesLibrary.GetFileAsync(imageName);

                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    bitmapImage.SetSource(fileStream);
                    myMediaPlayerElement.PosterSource = bitmapImage;
                }
            }
        }
        /// <summary>
        /// This is called after the Camera capture is done and the picture is to be displayed
        ///
        /// </summary>
        private async void LoadPicture()
        {
            try

            {
                // Open the picture file captured from the camera
                if (string.IsNullOrEmpty(pictureName))
                {
                    return;
                }
                Windows.Storage.StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(pictureName);

                if (file != null)
                {
                    // Open a stream for the selected file.
                    // The 'using' block ensures the stream is disposed
                    // after the image is loaded.
                    using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                               await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                    {
                        // Set the image source to the selected bitmap.
                        Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                            new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                        bitmapImage.SetSource(fileStream);
                        FacePhoto.Source = bitmapImage;
                    }
                }
            }
            catch (Exception ex)
            {
                SolidColorBrush brush = new SolidColorBrush(Windows.UI.Colors.Red);
                Status.Foreground = brush;
                Status.Text       = "Error Loading picture : " + ex.Message;
            }
        }
Example #49
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            ItemsNuevos.Clear();
            cnvCanvasSelected.Children.Clear();
            Items.Clear();
            cnvCanvas.Children.Clear();
            LoadingControl.IsLoading = true;
            resultadosDistancia.Clear();

            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");
            storageFile = await openPicker.PickSingleFileAsync();


            if (storageFile != null)
            {
                var stream = await storageFile.OpenAsync(FileAccessMode.Read);

                randomAccessStreamImage = stream;
                Stream streamImage = randomAccessStreamImage.AsStream();
                byte[] b;

                using (BinaryReader br = new BinaryReader(streamImage))
                {
                    b = br.ReadBytes((int)streamImage.Length);
                }
                byte[] byteArray;
                using (Windows.Storage.Streams.IRandomAccessStream fileStream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    bitmapImage.SetSource(fileStream);
                    width  = bitmapImage.PixelWidth;
                    heigth = bitmapImage.PixelHeight;
                    if (width > 400)
                    {
                        constante = 1 / (width / 600);

                        width  = width * constante;
                        heigth = heigth * constante;
                    }
                    byteArray = new byte[fileStream.AsStream().Length];



                    cnvCanvas.Width          = (int)width;
                    cnvCanvas.Height         = (int)heigth;
                    cnvCanvasSelected.Width  = (int)width;
                    cnvCanvasSelected.Height = (int)heigth;

                    imagePreview.Width  = (int)width;
                    imagePreview.Height = (int)heigth;
                    imagePreview.Source = bitmapImage;

                    imagePreview.Opacity = 0.4;


                    vsproject = vs.Last().ToString();


                    try
                    {
                        var client = new HttpClient();
                        client.DefaultRequestHeaders.Add("Prediction-Key", localSettings.Values["apiKeyCV"] as string);
                        ByteArrayContent bytearrayContent = new ByteArrayContent(b);
                        bytearrayContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
                        var projecto       = vsproject;
                        var byteArrayNuevo = bytearrayContent;
                        var result         = await client.PostAsync("https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/" + vsproject + "/image", bytearrayContent);

                        if (result.IsSuccessStatusCode)
                        {
                            var response = result.Content.ReadAsStringAsync().Result;

                            dynamic obj                 = JsonConvert.DeserializeObject <dynamic>(response);
                            int     contador            = 0;
                            var     dynamicImagePredict = obj.id;
                            idPredictedImage = (string)dynamicImagePredict;

                            foreach (var item in obj.predictions)
                            {
                                var resultadoCaja = item.boundingBox;
                                var resultadoTag  = item.tagName;
                                if (item.probability * 100 >= 75)
                                {
                                    imagePreview.Opacity    = 1;
                                    imagePreview.Visibility = Visibility.Visible;
                                    dibujarCaja(resultadoCaja, resultadoTag, item.probability);


                                    LoadingControl.IsLoading = false;

                                    contador += 1;
                                }
                                ;
                            }
                            txtResult.Text = "Se encontraron: " + contador.ToString() + " elementos";

                            SolidColorBrush solidColorBrushSalud = new SolidColorBrush(Windows.UI.Colors.Green);
                            txtResultSalud.Foreground = solidColorBrushSalud;

                            txtResultSalud.Text = "La salud del cultivo es OPTIMA";
                        }
                    }
                    catch (Exception ex)
                    {
                        var error = ex.Message.ToString();
                        throw;
                    }
                }
            }
        }