当前位置: 首页>>代码示例>>C#>>正文


C# FileOpenPicker.PickSingleFileAsync方法代码示例

本文整理汇总了C#中Windows.Storage.Pickers.FileOpenPicker.PickSingleFileAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FileOpenPicker.PickSingleFileAsync方法的具体用法?C# FileOpenPicker.PickSingleFileAsync怎么用?C# FileOpenPicker.PickSingleFileAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Storage.Pickers.FileOpenPicker的用法示例。


在下文中一共展示了FileOpenPicker.PickSingleFileAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ButtonFilePick_Click

        private async void ButtonFilePick_Click(object sender, RoutedEventArgs e)
        {
            var 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)
            {

                ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
                var savedPictureStream = await file.OpenAsync(FileAccessMode.Read);

                //set image properties and show the taken photo
                bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
                await bitmap.SetSourceAsync(savedPictureStream);
                BBQImage.Source = bitmap;
                BBQImage.Visibility = Visibility.Visible;

                (this.DataContext as BBQRecipeViewModel).imageSource = file.Path;
            }
        }
开发者ID:cheahengsoon,项目名称:Windows10UWP-HandsOnLab,代码行数:27,代码来源:BBQRecipePage.xaml.cs

示例2: MenuItem_Click

        private async void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            StorageFile file;
            var item = sender as MenuFlyoutItem;
            if (item.Tag.ToString() == "photo")
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".png");

                file = await openPicker.PickSingleFileAsync();
            }
            else
            {
                CameraCaptureUI captureUI = new CameraCaptureUI();
                captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
                captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);

                file = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
            }
            if (file != null)
            {
                // Application now has read/write access to the picked file
                var img = await UtilityHelper.LoadImage(file);
                imgSource.Source = img;
                fileStream = await file.OpenStreamForWriteAsync();
            }
        }
开发者ID:poumason,项目名称:DotblogsSampleCode,代码行数:31,代码来源:MainPage.xaml.cs

示例3: LoadImageUsingSetSource_Click

        private async void LoadImageUsingSetSource_Click(object sender, RoutedEventArgs e)
        {
            // This method loads an image into the WriteableBitmap using the SetSource method

            FileOpenPicker picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".bmp");

            StorageFile file = await picker.PickSingleFileAsync();

            // Ensure a file was selected
            if (file != null)
            {
                // Set the source of the WriteableBitmap to the image stream
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    try
                    {
                        await Scenario4WriteableBitmap.SetSourceAsync(fileStream);
                    }
                    catch (TaskCanceledException)
                    {
                        // The async action to set the WriteableBitmap's source may be canceled if the user clicks the button repeatedly
                    }
                }
            }
        }
开发者ID:oldnewthing,项目名称:old-Windows8-samples,代码行数:30,代码来源:Scenario4.xaml.cs

示例4: BackgroundButton_Click

      private async void BackgroundButton_Click(object sender, RoutedEventArgs e)
      {
        // Clear previous returned file name, if it exists, between iterations of this scenario
        OutputTextBlock.Text = "";

        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();
        if (file != null)
        {
          // Application now has read/write access to the picked file
          OutputTextBlock.Text = "Picked photo: " + file.Name;

          BitmapImage img = new BitmapImage();
          img = await ImageHelpers.LoadImage( file );
          MyPicture.Source = img;

        }
        else
        {
          OutputTextBlock.Text = "Operation cancelled.";
        }
      }
开发者ID:underhilld2,项目名称:BedSideClock,代码行数:27,代码来源:StartupPage.xaml.cs

示例5: OpenPicture_Click

        /// <summary>
        /// Open the image selection standard dialog
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event argument</param>
        private async void OpenPicture_Click(object sender, RoutedEventArgs e)
        {
            if (!this.showInProgress)
            {
                this.showInProgress = true;

                try
                {
                    var picker = new FileOpenPicker();

                    picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                    picker.ViewMode = PickerViewMode.Thumbnail;
                    picker.FileTypeFilter.Add(".jpg");
                    picker.FileTypeFilter.Add(".jpeg");

                    var file = await picker.PickSingleFileAsync();
                    if (file != null)
                    {
                        // open captured file and set the image source on the control
                        this.ocrData.PhotoStream = await file.OpenAsync(FileAccessMode.Read);
                    }
                }
                finally
                {
                    this.showInProgress = false;
                }
            }
        }
开发者ID:eirikdal,项目名称:ReciCamApp,代码行数:33,代码来源:PhotoSelector.xaml.cs

示例6: LoadKML

        public async System.Threading.Tasks.Task LoadKML(System.Collections.Generic.List<Windows.Devices.Geolocation.BasicGeoposition> mapdata)
        {
            Windows.Data.Xml.Dom.XmlLoadSettings loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings();
            loadSettings.ElementContentWhiteSpace = false;
            Windows.Data.Xml.Dom.XmlDocument kml = new Windows.Data.Xml.Dom.XmlDocument();
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add(".kml");
            Windows.Storage.IStorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                string[] stringSeparators = new string[] { ",17" };
                kml = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(file);
                var element = kml.GetElementsByTagName("coordinates").Item(0);
                string ats  = element.FirstChild.GetXml();

                string[] atsa = ats.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
                int size = atsa.Length-1;
                for (int i = 0; i < size; i++)
                {
                    string[] coord = atsa[i].Split(',');
                    double longi = Convert.ToDouble(coord[0]);
                    double lati = Convert.ToDouble(coord[1]);
                    mapdata.Add(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = lati, Longitude = longi });
                }
            }
        }
开发者ID:justasmalinauskas,项目名称:JustMeasure,代码行数:28,代码来源:LoadMaps.cs

示例7: Import

        public static async Task<SaveAllSpecies> Import()
        {
            FileOpenPicker importPicker = new FileOpenPicker();
            importPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            importPicker.FileTypeFilter.Add(".xml");
            importPicker.CommitButtonText = "Import";
            StorageFile file = await importPicker.PickSingleFileAsync();
            if (null != file)
            {
                using (var stream = await file.OpenAsync(FileAccessMode.Read))
                {
                    using (Stream inputStream = stream.AsStreamForRead())
                    {
                        SaveAllSpecies data;
                        XmlSerializer serializer = new XmlSerializer(typeof(SaveAllSpecies));
                        using (XmlReader xmlReader = XmlReader.Create(inputStream))
                        {
                            data = (SaveAllSpecies)serializer.Deserialize(xmlReader);
                        }
                        await inputStream.FlushAsync();
                        return data;
                    }                    
                }
            }
            else
            {
                //nothing
            }

            return null;
        }
开发者ID:kbo4sho,项目名称:Swarm,代码行数:31,代码来源:ImportExportHelper.cs

示例8: GetThumbnailButton_Click

        private async void GetThumbnailButton_Click(object sender, RoutedEventArgs e)
        {
            rootPage.ResetOutput(ThumbnailImage, OutputTextBlock);

            // Pick a document
            FileOpenPicker openPicker = new FileOpenPicker();
            foreach (string extension in FileExtensions.Document)
            {
                openPicker.FileTypeFilter.Add(extension);
            }

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                const ThumbnailMode thumbnailMode = ThumbnailMode.DocumentsView;
                const uint size = 100;
                using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, size))
                {
                    if (thumbnail != null)
                    {
                        MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailMode.ToString(), size, file, thumbnail, false);
                    }
                    else
                    {
                        rootPage.NotifyUser(Errors.NoIcon, NotifyType.StatusMessage);
                    }
                }
            }
            else
            {
                rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage);
            }

        }
开发者ID:mbin,项目名称:Win81App,代码行数:34,代码来源:Scenario3.xaml.cs

示例9: GetImageFromImport

        public async static Task<PhotoPageArguements> GetImageFromImport(bool isNewDocument = true)
        {
            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;

            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

            picker.FileTypeFilter.Add(".jpg");

            var file = await picker.PickSingleFileAsync();

            PhotoPageArguements arguments = null;

            if (file != null)
            {
                var temporaryFolder = ApplicationData.Current.TemporaryFolder;

                await file.CopyAsync(temporaryFolder,
                    file.Name, NameCollisionOption.ReplaceExisting);

                file = await temporaryFolder.TryGetFileAsync(file.Name);

                if (file != null)
                {
                    arguments = await ImageService.GetPhotoPageArguements(file, isNewDocument);
                }
            }

            return arguments;
        }
开发者ID:epustovit,项目名称:Scanner,代码行数:31,代码来源:ImageService.cs

示例10: CompareFilesButton_Click

 /// <summary>
 /// Compares a picked file with sample.dat
 /// </summary>
 private async void CompareFilesButton_Click(object sender, RoutedEventArgs e)
 {
     rootPage.ResetScenarioOutput(OutputTextBlock);
     StorageFile file = rootPage.sampleFile;
     if (file != null)
     {
         FileOpenPicker picker = new FileOpenPicker();
         picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
         picker.FileTypeFilter.Add("*");
         StorageFile comparand = await picker.PickSingleFileAsync();
         if (comparand != null)
         {
             if (file.IsEqual(comparand))
             {
                 OutputTextBlock.Text = "Files are equal";
             }
             else
             {
                 OutputTextBlock.Text = "Files are not equal";
             }
         }
         else
         {
             OutputTextBlock.Text = "Operation cancelled";
         }
     }
     else
     {
         rootPage.NotifyUserFileNotExist();
     }
 }
开发者ID:mbin,项目名称:Win81App,代码行数:34,代码来源:Scenario9.xaml.cs

示例11: Load_File

		public async static Task<SimpleCollada> Load_File()
        {
            try
            {
				SimpleCollada col_scenes = null;
				XmlSerializer sr = new XmlSerializer(typeof(SimpleCollada));
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                openPicker.FileTypeFilter.Add(".xml");
                openPicker.FileTypeFilter.Add(".dae");
                StorageFile file = await openPicker.PickSingleFileAsync();
                if (file != null)
                {
                    var stream = await file.OpenStreamForReadAsync();
                    col_scenes = (SimpleCollada)(sr.Deserialize(stream));
                }
               
				return col_scenes;
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.ToString());
                //Console.ReadLine();
				return null;
            }			
		}
开发者ID:dolkensp,项目名称:OTWB,代码行数:27,代码来源:SimpleCollada.cs

示例12: PickOpenFileAsync

		public static async Task<StorageFile> PickOpenFileAsync(string[] extensions)
		{
			StorageFile file = null;
			try
			{
				Task<StorageFile> fileTask = null;
				await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, delegate
				{
					var openPicker = new FileOpenPicker
					{
						ViewMode = PickerViewMode.List,
						SuggestedStartLocation = PickerLocationId.DocumentsLibrary
					};

					foreach (var ext in extensions)
					{
						openPicker.FileTypeFilter.Add(ext);
					}
					fileTask = openPicker.PickSingleFileAsync().AsTask();
				});

				file = await fileTask;
			}
			catch (Exception ex)
			{
				await Logger.AddAsync(ex.ToString(), Logger.FileErrorLogFilename);
			}
			finally
			{
				SetLastPickedOpenFile(file);
				SetLastPickedOpenFileMRU(file);
			}
			return file;
		}
开发者ID:lolluslollus,项目名称:Utilz,代码行数:34,代码来源:Pickers.cs

示例13: Execute

        public async override void Execute(object parameter)
        {
            var album = parameter as AlbumItem;

            if (album == null)
            {
                var args = parameter as ItemClickEventArgs;
                if(args != null)
                album = args.ClickedItem as AlbumItem;
            }

            var openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".gif");
            // Windows Phone launches the picker, then freezes the app. We need
            // to pick it up again on OnActivated.
#if WINDOWS_PHONE_APP
            App.OpenFilePickerReason = OpenFilePickerReason.OnPickingAlbumArt;
            App.SelectedAlbumItem = album;
            openPicker.PickSingleFileAndContinue();
#else
            var file = await openPicker.PickSingleFileAsync();
            if (file == null) return;
            var byteArray = await ConvertImage.ConvertImagetoByte(file);
            await App.MusicMetaService.SaveAlbumImageAsync(album, byteArray);
            await Locator.MusicLibraryVM._albumDatabase.Update(album);
#endif
        }
开发者ID:robUx4,项目名称:vlc-winrt,代码行数:34,代码来源:ChangeAlbumArtCommand.cs

示例14: Execute

        public async void Execute(object parameter)
        {
            try
            {
                App.OpenFilePickerReason = OpenFilePickerReason.OnOpeningVideo;
                var picker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.List,
                    SuggestedStartLocation = PickerLocationId.VideosLibrary
                };
                foreach (var ext in _allowedExtensions)
                    picker.FileTypeFilter.Add(ext);


#if WINDOWS_APP
                StorageFile file = null;
                file = await picker.PickSingleFileAsync();
                if (file != null)
                {
                    LogHelper.Log("Opening file: " + file.Path);
                    await Locator.MediaPlaybackViewModel.OpenFile(file);
                }
                else
                {
                    LogHelper.Log("Cancelled");
                }
                App.OpenFilePickerReason = OpenFilePickerReason.Null;
#else
            picker.PickSingleFileAndContinue();
#endif
            }
            catch { }
        }
开发者ID:robUx4,项目名称:vlc-winrt,代码行数:33,代码来源:PickVideoCommand.cs

示例15: MakeParameterForOffLine

        /// <summary>
        /// MakeParameterForOffLine : Make Parameter For Reports on Device
        /// </summary>
        /// <returns>Parameter String</returns>
        public static async Task<string> MakeParameterForOffLine()
        {
            string strOzdPath = string.Empty;
            string strFinalPath = string.Empty;

            try
            {
                FileOpenPicker foPicker = new FileOpenPicker();

                foPicker.ViewMode = PickerViewMode.List;
                foPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                foPicker.FileTypeFilter.Add(".ozd");

                StorageFile sfiFile = await foPicker.PickSingleFileAsync();
                StorageFolder sfoFolder = ApplicationData.Current.LocalFolder;
                
                if (sfiFile != null)
                {
                    // await sfiFile.CopyAsync(sfoFolder, sfiFile.Name, NameCollisionOption.ReplaceExisting);
                    await sfiFile.CopyAsync(sfoFolder, "insert.ozd", NameCollisionOption.ReplaceExisting);

                    //strOzdPath = ApplicationData.Current.LocalFolder.Path + "\\" + sfiFile.Name;
                    strOzdPath = ApplicationData.Current.LocalFolder.Path + "\\insert.ozd";
                    StorageFile sfoTmpFile = await StorageFile.GetFileFromPathAsync(strOzdPath);
                    strFinalPath = "connection.openfile=" + strOzdPath;
                }                
            }
            catch (Exception ex)
            {
                strFinalPath = "";
            }

            return strFinalPath;
        }
开发者ID:paraneye,项目名称:WinApp,代码行数:38,代码来源:ReportUtil.cs


注:本文中的Windows.Storage.Pickers.FileOpenPicker.PickSingleFileAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。