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


C# Pickers.FileOpenPicker类代码示例

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


FileOpenPicker类属于Windows.Storage.Pickers命名空间,在下文中一共展示了FileOpenPicker类的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: 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

示例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: BtPickVideoClick

        private async void BtPickVideoClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;
            FileOpenPicker openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.VideosLibrary
            };
            openPicker.FileTypeFilter.Add(".avi");
            openPicker.FileTypeFilter.Add(".mp4");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                var client = new VideosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);
                Video video = new Video { Title = file.DisplayName, Tags = file.DisplayName, Synopse = file.DisplayName };
                this.tblock_PostVideoResult.Text = await client.CreateVideoAsync(file, video);
            }
            else
            {
                this.tblock_PostVideoResult.Text = "Error reading file";
            }

        }
开发者ID:stvkoch,项目名称:sapo-services-sdk,代码行数:27,代码来源:AddVideo.xaml.cs

示例5: BtnBrowse_OnClick

 private void BtnBrowse_OnClick(object sender, RoutedEventArgs e)
 {
     var picker = new FileOpenPicker();
     picker.FileTypeFilter.Add(".gif");
     picker.ContinuationData["context"] = "addGifImage";
     picker.PickSingleFileAndContinue();
 }
开发者ID:thomaslevesque,项目名称:XamlAnimatedGif,代码行数:7,代码来源:GifTestPage.xaml.cs

示例6: GetPictureFromGalleryAsync

        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 "";
		}
开发者ID:india-rose,项目名称:xamarin-indiarose,代码行数:31,代码来源:MediaService.cs

示例7: SelectFilesButton_Click

        private async void SelectFilesButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker filePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.List,
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                FileTypeFilter = { "*" }
            };

            IReadOnlyList<StorageFile> pickedFiles = await filePicker.PickMultipleFilesAsync();

            if (pickedFiles.Count > 0)
            {
                this.storageItems = pickedFiles;

                // Display the file names in the UI.
                string selectedFiles = String.Empty;
                for (int index = 0; index < pickedFiles.Count; index++)
                {
                    selectedFiles += pickedFiles[index].Name;

                    if (index != (pickedFiles.Count - 1))
                    {
                        selectedFiles += ", ";
                    }
                }
                this.rootPage.NotifyUser("Picked files: " + selectedFiles + ".", NotifyType.StatusMessage);

                ShareStep.Visibility = Visibility.Visible;
            }
        }
开发者ID:oldnewthing,项目名称:old-Windows8-samples,代码行数:31,代码来源:ShareFiles.xaml.cs

示例8: AddButtonClick_OnClick

        private async void AddButtonClick_OnClick(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".jpg");
            var files = await picker.PickMultipleFilesAsync();

            TreeMap.Children.Clear();

            var sources = new List<BitmapImage>();
            foreach (var file in files)
            {
                var stream = (await file.OpenStreamForReadAsync()).AsRandomAccessStream();//await file.GetScaledImageAsThumbnailAsync(ThumbnailMode.PicturesView, 300);
                var imageSource = new BitmapImage();
                await imageSource.SetSourceAsync(stream);

                sources.Add(imageSource);

                var image = new Image();
                image.Stretch = Stretch.UniformToFill;
                image.Source = imageSource;
                TreeMap.Children.Add(image);
            }

            MosaicImage.Source = sources;
        }
开发者ID:nguyenkien,项目名称:MosaicImageControls,代码行数:25,代码来源:MainPage.xaml.cs

示例9: SelectPictureButton_Click

        private async void SelectPictureButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();  //允许用户打开和选择文件的UI
            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();  //storageFile:提供有关文件及其内容以及操作的方式
            if (file != null)
            {
                path = file.Path;
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap 
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.DecodePixelWidth = 600; //match the target Image.Width, not shown
                    await bitmapImage.SetSourceAsync(fileStream);
                    img.Source = bitmapImage;
                }
            }
            else
            {
                var i = new MessageDialog("error with picture").ShowAsync();
            }
        }
开发者ID:Crazytinal,项目名称:xiancao_project,代码行数:27,代码来源:AddTaskPage.xaml.cs

示例10: ExecuteSelectPictureCommand

        private async void ExecuteSelectPictureCommand()
        {
            try
            {
                Busy = true;

                
                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)
                {
                    // Copy the file into local folder
                    await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting);
                    // Save in the ToDoItem
                    TodoItem.ImageUri = new Uri("ms-appdata:///local/" + file.Name);
                }
            }
            finally { Busy = false; }
        }
开发者ID:MuffPotter,项目名称:201505-MVA,代码行数:26,代码来源:TodoItemViewModel.cs

示例11: Add_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;
        }
开发者ID:sarthakbhol,项目名称:Windows10AppSamples,代码行数:26,代码来源:MainPage.xaml.cs

示例12: seleccionarImagen

        private async void seleccionarImagen(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".png");
            file = await picker.PickSingleFileAsync();

            BitmapImage image = new BitmapImage();
            try
            {
                using (var stream = await file.OpenAsync(FileAccessMode.Read))
                {
                    await image.SetSourceAsync(stream);
                }
                ImageBrush brush = new ImageBrush();
                brush.Stretch = Stretch.UniformToFill;
                brush.ImageSource = image;
                imagen.Fill = brush;
            }
            catch (Exception exception)
            {

            }
            
        }
开发者ID:wgcarvajal,项目名称:HuellitaW10,代码行数:25,代码来源:AgregarFotoMascotaPage.xaml.cs

示例13: openFileButton_Click

        private async void openFileButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var pi = new FileOpenPicker();
                pi.SuggestedStartLocation = PickerLocationId.Downloads;
                pi.FileTypeFilter.Add(".dll");
                //{
                //    //SettingsIdentifier = "PE Viewer",
                //    SuggestedStartLocation = PickerLocationId.Downloads,
                //    ViewMode = PickerViewMode.List
                //};
                ////pi.FileTypeFilter.Add("DLL and EXE files|*.dll;*.exe");
                ////pi.FileTypeFilter.Add("All files|*.*");

                var fi = await pi.PickSingleFileAsync();

                var fiStream = await fi.OpenAsync(Windows.Storage.FileAccessMode.Read);
                var stream = fiStream.OpenRead();

                var buf = await ReadAll(stream);

                var bufStream = new MemoryStream(buf);

                var pe = new PEFile();
                pe.ReadFrom(new BinaryStreamReader(bufStream, new byte[32]));

                LayoutRoot.Children.Add(new PEFileView { DataContext = pe });
            }
            catch (Exception error)
            {
                openFileButton.Content = error;
            }
        }
开发者ID:BGCX261,项目名称:zoompe-git,代码行数:34,代码来源:MainPage.xaml.cs

示例14: UploadtoParse

        public async void UploadtoParse()
        {

            ParseClient.Initialize("oVFGM355Btjc1oETUvhz7AjvNbVJZXFD523abVig", "4FpFCQyO7YVmo2kMgrlymgDsshAvTnGAtQcy9NHl");

            var filePicker = new FileOpenPicker();
            filePicker.FileTypeFilter.Add(".png");
            var pickedfile = await filePicker.PickSingleFileAsync();
            using (var randomStream = (await pickedfile.OpenReadAsync()))
            {
                using (var stream = randomStream.AsStream())
                {
                    //byte[] data = System.Text.Encoding.UTF8.GetBytes("Working at Parse is great!");
                    ParseFile file = new ParseFile("resume1.png", stream);

                    await file.SaveAsync();

                    var jobApplication = new ParseObject("JobApplication");
                    jobApplication["applicantName"] = "jambor";
                    jobApplication["applicantResumeFile"] = file;
                    await jobApplication.SaveAsync();

                }
            }

          

        }
开发者ID:JamborYao,项目名称:UwpStart,代码行数:28,代码来源:ParseCloud.xaml.cs

示例15: OnOpenDotnet

        public async void OnOpenDotnet()
        {
            try
            {
                var picker = new FileOpenPicker()
                {
                    SuggestedStartLocation = PickerLocationId.DocumentsLibrary
                };
                picker.FileTypeFilter.Add(".txt");

                StorageFile file = await picker.PickSingleFileAsync();
                if (file != null)
                {
                    IRandomAccessStreamWithContentType wrtStream = await file.OpenReadAsync();
                    Stream stream = wrtStream.AsStreamForRead();
                    using (var reader = new StreamReader(stream))
                    {
                        text1.Text = await reader.ReadToEndAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                var dlg = new MessageDialog(ex.Message, "Error");
                await dlg.ShowAsync();
            }
        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:27,代码来源:MainPage.xaml.cs


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