win8平板App - 文件选择和调用摄像头
1、文件选择
FileOpenPicker filePicker = new FileOpenPicker() { ViewMode = PickerViewMode.Thumbnail };
//只有图片
filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
FillDecoderExtensions(filePicker.FileTypeFilter);
StorageFile imageFile = await filePicker.PickSingleFileAsync();
if (imageFile != null)
{
fileStream = await imageFile.OpenAsync(FileAccessMode.Read);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileStream);
Image choosedImage = new Image();
choosedImage.Source = bitmapImage;
}
//任意文件
filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
filePicker.FileTypeFilter.Add("*");
StorageFile choosedFile = await filePicker.PickSingleFileAsync();
if (choosedFile != null)
{
const ThumbnailMode thumbnailMode = ThumbnailMode.DocumentsView;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(await choosedFile.GetThumbnailAsync(thumbnailMode));
Image choosedFileThumbnail = new Image();
choosedFileThumbnail.Source = bitmapImage;
}
2、调用摄像头
Windows.Media.Capture.CameraCaptureUI dialog = new Windows.Media.Capture.CameraCaptureUI();
StorageFile imageFile = await dialog.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.PhotoOrVideo);
if (imageFile != null)
{
fileStream = await imageFile.OpenAsync(FileAccessMode.Read);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(fileStream);
Image choosedImage = new Image();
choosedImage.Source = bitmapImage;
}