2016-04-22 44 views

回答

0

这不是很漂亮,但它现在的作品。 我声明了名为myimageList和alt-myImageList的ObservableCollection类型的两个全局变量。我只是检查这些集合的大小,并从这一点开始。

这是代码:

 private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1) 
    { 
     FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs; 

     if (args != null) 
     { 
      if (args.Files.Count == 0) return; 

      view.Activated -= viewActivated; 

      foreach (var item in args.Files) 
      { 
       // instead of item args.Files[0]; 
       StorageFile storageFile = item; 
       var stream = await storageFile.OpenAsync(FileAccessMode.Read); 
       var bitmapImage = new BitmapImage(); 
       await bitmapImage.SetSourceAsync(stream); 

       var wbImage = new WriteableBitmap(bitmapImage.PixelWidth, bitmapImage.PixelHeight); 
       wbImage.SetSource(stream); 

       //var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream); 
       //bitmapImage.UriSource = new Uri(item.Path, UriKind.Absolute); 

       if (myImageList.Count < 4) 
       { 
        myImageList.Add(bitmapImage); 
        alt_myImageList.Add(item); 
        ErrorMessage.Text = ""; 
       } 
       else 
       { 
        ErrorMessage.Text = "Please pick not more than 4 pictures"; 
       } 
      } 
     }