本文整理汇总了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;
}
}
示例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;
}
示例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
}
}
}
}
示例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";
}
}
示例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();
}
示例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 "";
}
示例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;
}
}
示例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;
}
示例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();
}
}
示例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; }
}
示例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;
}
示例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)
{
}
}
示例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;
}
}
示例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();
}
}
}
示例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();
}
}