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