private async void ButtonCamera_Click(object sender, RoutedEventArgs e) { CameraCaptureUI captureUI = new CameraCaptureUI(); captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; captureUI.PhotoSettings.CroppedSizeInPixels = new Size(600, 600); StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo != null) { BitmapImage bmp = new BitmapImage(); IRandomAccessStream stream = await photo. OpenAsync(FileAccessMode.Read); bmp.SetSource(stream); BBQImage.Source = bmp; FileSavePicker savePicker = new FileSavePicker(); savePicker.FileTypeChoices.Add ("jpeg image", new List<string>() { ".jpeg" }); savePicker.SuggestedFileName = "New picture"; StorageFile savedFile = await savePicker.PickSaveFileAsync(); (this.DataContext as BBQRecipeViewModel).imageSource = savedFile.Path; if (savedFile != null) { await photo.MoveAndReplaceAsync(savedFile); } } }
private async void HandleAddImageCommand() { var camera = new CameraCaptureUI(); var photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo); ImageInfoViewModel imageInfo = null; if (photo != null) { var extension = photo.FileType; var bytearray = File.ReadAllBytes(photo.Path); var name = photo.DisplayName; imageInfo = new ImageInfoViewModel() { OriginalName = name, FileExstension = extension, ByteArrayContent = bytearray }; var image = new ImageViewModel() { ImageInfo = imageInfo, ImageUrl = photo.Path }; this.images.Add(image); } else { // TODO: Set real notification var dialog = new MessageDialog("Something Get Wrong"); await dialog.ShowAsync(); } }
// アプリバーの撮影ボタンから画像ファイルを開く private async void buttonPhoto_Click(object sender, RoutedEventArgs e) { // エラーが発生した時の文言 var errorMessage = default(string); // 撮影ダイアログを表示して、撮影後の画像ファイルを取得する var capture = new CameraCaptureUI(); try { var file = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { // ファイルを読み込んで画像を表示する srcBitmap = await CreateBitmapAsync(file); // 元画像をImageコントロールへ表示する effectedImage.Source = srcBitmap; } else { errorMessage = "撮影処理がキャンセルされました"; } } catch (Exception ex) { errorMessage = "カメラデバイスの起動に失敗しました\n" + ex.Message; } // エラーが発生した場合はメッセージダイアログでユーザーに通知する if (!string.IsNullOrEmpty(errorMessage)) { var msgDlg = new MessageDialog(errorMessage); await msgDlg.ShowAsync(); } }
private async void Button_Click(object sender, RoutedEventArgs e) { var captureUI = new CameraCaptureUI(); captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo == null) { return; } var b = new BitmapImage(new Uri(photo.Path)); img.Source = b; var imgStream = await photo.OpenAsync(FileAccessMode.Read); txt.Text = "Recognizing..."; var faces = await OxFaceRecognizer.DetectAsync(imgStream.AsStream(), true, true, true, false); txt.Text = "Done"; if (faces != null && faces.Length > 0) { var f = faces[0]; txt.Text = $"{f.Attributes.Gender}, {f.Attributes.Age}"; rect.Visibility = Visibility.Visible; Canvas.SetLeft(rect, f.FaceRectangle.Left); Canvas.SetTop(rect, f.FaceRectangle.Top); rect.Height = f.FaceRectangle.Height; rect.Width = f.FaceRectangle.Width; } }
private async void button_Click(object sender, RoutedEventArgs e) { CameraCaptureUI captureUI = new CameraCaptureUI(); captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo == null) { // User cancelled photo capture return; } IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read); BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(); SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource(); await bitmapSource.SetBitmapAsync(softwareBitmapBGR8); imageControl.Source = bitmapSource; }
public static async Task<IStorageFile> CameraCapture() { var cameraUi = new CameraCaptureUI(); cameraUi.PhotoSettings.AllowCropping = false; cameraUi.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.MediumXga; return await cameraUi.CaptureFileAsync(CameraCaptureUIMode.Photo); }
private async void CapturePhoto_Click(object sender, RoutedEventArgs e) { try { var dialog = new CameraCaptureUI(); var aspectRatio = new Size(16, 9); dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { var bitmapImage = new BitmapImage(); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read)) { bitmapImage.SetSource(fileStream); } CapturedPhoto.Source = bitmapImage; // Store the file path in Application Data appSettings[photoKey] = file.Path; ResetButton.Visibility = Visibility.Visible; } } catch (Exception ex) { } }
/// <summary> /// This is the click handler for the 'CaptureButton' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void CapturePhoto_Click(object sender, RoutedEventArgs e) { try { rootPage.NotifyUser("", NotifyType.StatusMessage); // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo CameraCaptureUI dialog = new CameraCaptureUI(); Size aspectRatio = new Size(16, 9); dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { BitmapImage bitmapImage = new BitmapImage(); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read)) { bitmapImage.SetSource(fileStream); } CapturedPhoto.Source = bitmapImage; ResetButton.Visibility = Visibility.Visible; // Store the file path in Application Data appSettings[photoKey] = file.Path; } else { rootPage.NotifyUser("No photo captured.", NotifyType.StatusMessage); } } catch (Exception ex) { rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage); } }
private static async Task<ImageModel> Capture() { var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); // Get the desired camera by panel DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back); if (desiredDevice == null) { Debug.Write("no Camrea"); return null; } CameraCaptureUI cameraUI = new CameraCaptureUI(); cameraUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; cameraUI.PhotoSettings.AllowCropping = false; //cameraUI.PhotoSettings.CroppedSizeInPixels = new Size(1280,720); StorageFile photo = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo == null) return null; IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read); BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); decoder = await BitmapDecoder.CreateAsync( await decoder.GetThumbnailAsync()); SoftwareBitmap bitmapBgr8 = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); SoftwareBitmapSource imgsource = new SoftwareBitmapSource(); await imgsource.SetBitmapAsync(bitmapBgr8); ImageModel imgModel = new ImageModel() { ImgFile = photo, ThumbnailImage = imgsource }; return imgModel; }
/// <summary> /// This is the click handler for the 'CaptureButton' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void CaptureVideo_Click(object sender, RoutedEventArgs e) { try { rootPage.NotifyUser("", NotifyType.StatusMessage); // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo CameraCaptureUI dialog = new CameraCaptureUI(); dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video); if (file != null) { IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); CapturedVideo.SetSource(fileStream, "video/mp4"); ResetButton.Visibility = Visibility.Visible; // Store the file path in Application Data appSettings[videoKey] = file.Path; } else { rootPage.NotifyUser("No video captured.", NotifyType.StatusMessage); } } catch (Exception ex) { rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage); } }
private async void Camera_Click(object sender, RoutedEventArgs e) { CameraCaptureUI captureUI = new CameraCaptureUI(); captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; captureUI.PhotoSettings.AllowCropping = false; StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); StorageFolder storageFolder = KnownFolders.CameraRoll; if (photo == null || storageFolder == null) { // Użytkownik anulował robienie zdjęcia return; } StorageFile storageFile = await storageFolder.CreateFileAsync( "PatronagePhoto.jpg", CreationCollisionOption.GenerateUniqueName); using (Stream outputStream = await storageFile.OpenStreamForWriteAsync()) { using (Stream photoStream = await photo.OpenStreamForReadAsync()) await photoStream.CopyToAsync(outputStream); } }
public void TakePicture(int maxPixelDimension, int percentQuality, Action<Stream> pictureAvailable, Action assumeCancelled) { var dispatcher = this.GetService<IMvxViewDispatcherProvider>(); dispatcher.Dispatcher.RequestMainThreadAction( async () => { // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo var dialog = new CameraCaptureUI(); var aspectRatio = new Size(16, 9); dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; // HACK HACK! dialog.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.SmallVga; dialog.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; var file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { BitmapImage bitmapImage = new BitmapImage(); var memoryStream = new MemoryStream(); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read)) { var conventional = fileStream.AsStreamForRead(); conventional.CopyTo(memoryStream); } pictureAvailable(memoryStream); } else { assumeCancelled(); } }); }
public async Task<Stream> CaptureAsync() { var dialog = new MessageDialog("Would you like to use your camera or select a picture from your library?"); dialog.Commands.Add(new UICommand("I'd like to use my camera", null, "camera")); dialog.Commands.Add(new UICommand("I already have the picture", null, "picker")); IStorageFile photoFile; var command = await dialog.ShowAsync(); if ((string)command.Id == "camera") { var cameraCapture = new CameraCaptureUI(); photoFile = await cameraCapture.CaptureFileAsync(CameraCaptureUIMode.Photo); } else { var photoPicker = new FileOpenPicker(); photoPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; photoPicker.FileTypeFilter.Add(".png"); photoPicker.FileTypeFilter.Add(".jpg"); photoPicker.FileTypeFilter.Add(".jpeg"); photoFile = await photoPicker.PickSingleFileAsync(); } if (photoFile == null) return null; var raStream = await photoFile.OpenAsync(FileAccessMode.Read); return raStream.AsStream(); }
private async void ExecuteTakePictureCommand() { try { Busy = true; StorageFile file = null; if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Media.Capture.CameraCaptureUI")) { // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo CameraCaptureUI dialog = new CameraCaptureUI(); Size aspectRatio = new Size(16, 9); dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); } 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; } }
private async void kameraBtn_Click(object sender, RoutedEventArgs e) { ApplicationView.GetForCurrentView().TitleBar.BackgroundColor = Colors.Red; // Uygulamanın title barı kırmızı olur ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false; // Ekran screen shoot alınamaz. var client = new TelemetryClient(); client.TrackEvent("ResimCekButonunaTiklandi"); var camera = new CameraCaptureUI(); camera.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; camera.PhotoSettings.AllowCropping = true; var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo); // resmi azure'a upload etmek için önce WindowsAzure.Storage 'ı nugetten ekle // var acount= CloudStorageAccount.Parse(""); // var blobClient = account.CreateCloudBlobClient(); // var folder = blobClient.GetBlockBlobReference("images"); // burada azure'da blob'un içinde images klasorunde profile.jpg adında bir alan oluşturup çekilen fotoğraf buraya upload edilir. // var blobFile = folder.GetBlockBlobReference("profile.jpg"); // blobFile.UploadFromFileAsync(file); }
private async Task faiFoto() { CameraCaptureUI dialog = new CameraCaptureUI(); Size aspectRatio = new Size(16, 9); dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); }
private async void CameraCapture() { CameraCaptureUI dialog = new CameraCaptureUI(); Size aspectRatio = new Size(16, 9); dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); // TODO: Post photo to service for processing. }
private async void abb_camera_Click(object sender, RoutedEventArgs e) { CameraCaptureUI dialog = new CameraCaptureUI(); Size aspectRatio = new Size(16, 9); dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); }
/// <summary> /// CameraCaptureUIを起動する /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void buttonCameraCaptureUI_Click(object sender, RoutedEventArgs e) { var dialog = new CameraCaptureUI(); dialog.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; var file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { await new Windows.UI.Popups.MessageDialog(file.Path, "撮影結果").ShowAsync(); } }
private async void InitCamera() { var camera = new CameraCaptureUI(); var photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo != null) { img.Source = new BitmapImage(new Uri(photo.Path)); } }
public async Task<StorageFile> GetPhotoFromCamera() { var camera = new CameraCaptureUI(); camera.PhotoSettings.AllowCropping = false; var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo); return file; }
private async void Button_Click_3(object sender, RoutedEventArgs e) { var camera = new CameraCaptureUI(); camera.VideoSettings.Format = CameraCaptureUIVideoFormat.Wmv; var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Video); if (file != null) { //不要求实现显示 } }
private async void OpenWebcam_Click(object sender, RoutedEventArgs e) { CameraCaptureUI dialog = new CameraCaptureUI(); dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; var file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video); if (file != null) { var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); player.SetSource(fileStream, file.FileType); } }
async private void btnCamera_Click(object sender, RoutedEventArgs e) { var ui = new CameraCaptureUI(); ui.PhotoSettings.CroppedAspectRatio = new Size(16,9); // 4,3 ya da benzer boyutları ekleyebilirisiniz var file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo); // Photo ,Video ya da PhotoVideo if (file != null) { bitmap = new BitmapImage(); bitmap.SetSource(await file.OpenAsync(FileAccessMode.Read)); imgVideo.Source = bitmap; } }
private async void Button_Click_2(object sender, RoutedEventArgs e) { /*打开相机并规定只能拍照*/ var camera = new CameraCaptureUI(); var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); BitmapImage bmp = new BitmapImage(); bmp.SetSource(stream); this.image.Source = bmp; } }
/// <summary> /// Permissions needed: Webcam, Microphone, PicturesLibrary, VideosLibrary /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Button_Click(object sender, RoutedEventArgs e) { // Capture photo var camera = new CameraCaptureUI(); image = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo); DisplayNotification("Photo captured", "Hey good lookin'"); // Save image to Pictures Library var saveImageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("test.jpg", CreationCollisionOption.ReplaceExisting); await image.CopyAndReplaceAsync(saveImageFile); DisplayNotification("Photo saved", "test.jpg"); }
private async void TakePicture() { var ui = new CameraCaptureUI(); ui.PhotoSettings.CroppedAspectRatio = new Size(4, 3); var file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file != null) { IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); NewItem.UpdateImage(fileStream); } }
async private void captureVideo(object sender, RoutedEventArgs e) { CameraCaptureUI videocamera = new CameraCaptureUI(); videocamera.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; videocamera.VideoSettings.AllowTrimming = true; videocamera.VideoSettings.MaxDurationInSeconds = 30; videocamera.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.HighestAvailable; StorageFile video = await videocamera.CaptureFileAsync(CameraCaptureUIMode.Video); if (video != null) { IRandomAccessStream stream = await video.OpenAsync(FileAccessMode.Read); myVideo.SetSource(stream, "video/mp4"); myVideo.Visibility = Visibility.Visible; } }
async private void captureImage(object sender, RoutedEventArgs e) { CameraCaptureUI camera = new CameraCaptureUI(); camera.PhotoSettings.CroppedAspectRatio = new Size(16, 9); StorageFile photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo); if (photo != null) { BitmapImage bmp = new BitmapImage(); IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read); bmp.SetSource(stream); myImage.Source = bmp; myImage.Visibility = Visibility.Visible; } }
private async void button_Click(object sender, RoutedEventArgs e) { CameraCaptureUI cc = new CameraCaptureUI(); cc.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; cc.PhotoSettings.CroppedAspectRatio = new Size(3, 4); cc.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable; StorageFile sf = await cc.CaptureFileAsync(CameraCaptureUIMode.Photo); if (sf != null) { BitmapImage bmp = new BitmapImage(); IRandomAccessStream rs = await sf.OpenAsync(FileAccessMode.Read); bmp.SetSource(rs); image.Source = bmp; } }