/// <summary> /// Launches default camera application to capture image /// </summary> /// <param name="options">may contains limit or mode parameters</param> public void captureImage(string options) { try { try { this.captureImageOptions = String.IsNullOrEmpty(options) ? CaptureImageOptions.Default : JSON.JsonHelper.Deserialize<CaptureImageOptions>(options); } catch (Exception ex) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message)); return; } cameraTask = new CameraCaptureTask(); cameraTask.Completed += this.cameraTask_Completed; cameraTask.Show(); } catch (Exception e) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e.Message)); } }
/// <summary> /// Launches default camera application to capture image /// </summary> /// <param name="options">may contains limit or mode parameters</param> public void captureImage(string options) { try { try { this.captureImageOptions = String.IsNullOrEmpty(options) ? CaptureImageOptions.Default : JSON.JsonHelper.Deserialize <CaptureImageOptions>(options); } catch (Exception ex) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message)); return; } cameraTask = new CameraCaptureTask(); cameraTask.Completed += this.cameraTask_Completed; cameraTask.Show(); } catch (Exception e) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e.Message)); } }
///<summary> ///Lunch default camera application to capture image ///</summary> ///<param name="options">may contains limit of mode parameters</param> /// public async void captureImage(string options) { try { try { string args = JSON.JsonHelper.Deserialize <string[]>(options)[0]; this.captureImageOptions = String.IsNullOrEmpty(args) ? CaptureImageOptions.Default : JSON.JsonHelper.Deserialize <CaptureImageOptions>(args); } catch (Exception ex) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message)); return; } cameraTask = new CameraCaptureUI(); cameraTask.PhotoSettings.AllowCropping = true; cameraTask.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable; cameraTask.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; StorageFile picture = await cameraTask.CaptureFileAsync(CameraCaptureUIMode.Photo); if (picture != null) { await picture.CopyAsync(Windows.Storage.KnownFolders.PicturesLibrary, picture.Name, Windows.Storage.NameCollisionOption.GenerateUniqueName); long size = 0; string modifiedDate = ""; var tasks = new List <Task <BasicProperties> >(); tasks.Add(picture.GetBasicPropertiesAsync().AsTask()); var result = await Task.WhenAll(tasks); foreach (var prop in result) { size = (long)prop.Size; modifiedDate = prop.DateModified.ToString(); } string imagePathOrContent = string.Empty; var readStream = await picture.OpenAsync(FileAccessMode.Read); var inputStream = readStream.GetInputStreamAt(0); var dataReaderFile = new DataReader(inputStream); var numByteLoaded = await dataReaderFile.LoadAsync((uint)readStream.Size); var byteString = new byte[numByteLoaded]; var imageBase64String = ""; dataReaderFile.ReadBytes(byteString); imageBase64String = Convert.ToBase64String(byteString); imagePathOrContent = "data:image/jpeg;base64," + imageBase64String; MediaFile data = new MediaFile(imagePathOrContent, picture.ContentType, picture.Name, size, modifiedDate); this.files.Add(data); if (files.Count < this.captureImageOptions.Limit) { //dosomething here } else { DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files)); files.Clear(); } } else { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error in capturing image")); } } catch (Exception ex) { var error = ex.Message.ToString(); DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error capturing image.")); } }