/// <summary> /// Starts continuously capturing still images. /// EventHandler must be set for capturing using <see cref="Capturing"/> /// and for completed using <see cref="CaptureCompleted"/> before calling this method. /// The camera must be in the <see cref="CameraState.Preview"/> state. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege> /// http://tizen.org/privilege/camera /// </privilege> /// <param name="count">The number of still images.</param> /// <param name="interval">The interval of the capture(milliseconds).</param> /// <param name="cancellationToken">The cancellation token to cancel capturing.</param> /// <seealso cref="CancellationToken"/> /// <remarks> /// If this is not supported, zero shutter lag occurs. The capture resolution could be /// changed to the preview resolution. This function causes the transition of the camera state /// from capturing to captured automatically and the corresponding Eventhandlers will be invoked. /// Each captured image will be delivered through Eventhandler set using the <see cref="Capturing"/> event. /// The preview should be restarted by calling the <see cref="StartPreview"/> method after capture is completed. /// </remarks> /// <exception cref="ArgumentOutOfRangeException">In case of invalid parameters.</exception> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception> public void StartCapture(int count, int interval, CancellationToken cancellationToken) { ValidateState(CameraState.Preview); if (count < 2) { throw new ArgumentOutOfRangeException(nameof(count), count, $"{nameof(count)} should be greater than one."); } if (interval < 0) { throw new ArgumentOutOfRangeException(nameof(interval), interval, $"{nameof(interval)} should be greater than or equal to zero."); } //Handle CancellationToken if (cancellationToken != CancellationToken.None) { cancellationToken.Register(() => { CameraErrorFactory.ThrowIfError(Native.StopContinuousCapture(_handle), "Failed to cancel the continuous capture"); SetState(CameraState.Captured); }); } CameraErrorFactory.ThrowIfError(Native.StartContinuousCapture(_handle, count, interval, _capturingCallback, _captureCompletedCallback, IntPtr.Zero), "Failed to start the continuous capture."); SetState(CameraState.Capturing); }
/// <summary> /// Starts camera auto-focusing, asynchronously. /// The camera must be in the <see cref="CameraState.Preview"/> or the <see cref="CameraState.Captured"/> state. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="continuous">Continuous auto focus.</param> /// <privilege> /// http://tizen.org/privilege/camera /// </privilege> /// <remarks> /// If continuous status is true, the camera continuously tries to focus. /// </remarks> /// <exception cref="ArgumentException">In case of invalid parameters.</exception> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception> public void StartFocusing(bool continuous) { ValidateState(CameraState.Preview, CameraState.Captured); CameraErrorFactory.ThrowIfError(Native.StartFocusing(_handle, continuous), "Failed to cancel the camera focus."); }
/// <summary> /// Stops camera auto focusing. /// The camera must be in the <see cref="CameraState.Preview"/> or the <see cref="CameraState.Captured"/> state. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege> /// http://tizen.org/privilege/camera /// </privilege> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception> public void StopFocusing() { ValidateState(CameraState.Preview, CameraState.Captured); CameraErrorFactory.ThrowIfError(Native.CancelFocusing(_handle), "Failed to cancel the camera focus."); }
private static void UnregisterDeviceStateChangedCallback() { CameraErrorFactory.ThrowIfError(Native.UnsetDeviceStateChangedCallback(_deviceStateCallbackId), "Unsetting device state changed callback failed"); _deviceStateChangedCallback = null; _deviceStateCallbackId = 0; }
/// <summary> /// Sets the position to move horizontally. /// </summary> /// <param name="type">The PTZ move type. <seealso cref="CameraPtzMoveType"/>.</param> /// <param name="panStep">The pan step.</param> /// <since_tizen> 3 </since_tizen> /// <feature> http://tizen.org/feature/camera </feature> /// <exception cref="ArgumentException">In case of invalid parameters.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> public void SetPan(CameraPtzMoveType type, int panStep) { ValidationUtil.ValidateEnum(typeof(CameraPtzMoveType), type, nameof(type)); CameraErrorFactory.ThrowIfError(Native.SetPan(_camera.GetHandle(), type, panStep), "Failed to set the camera pan type."); }
/// <summary> /// Changes the camera device. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="device">The hardware camera to access.</param> /// <remarks> /// If display reuse is set using <see cref="DisplayReuseHint"/> /// before stopping the preview, the display will be reused and last frame on the display /// can be kept even though camera device is changed. /// The camera must be in the <see cref="CameraState.Created"/>. /// </remarks> /// <exception cref="ArgumentException">In case of invalid parameters.</exception> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of the ChangeDevice feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> public void ChangeDevice(CameraDevice device) { ValidateState(CameraState.Created); ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device)); CameraErrorFactory.ThrowIfError(Native.ChangeDevice(_handle, device), "Failed to change the camera device"); }
private void RegisterPreviewCallback() { _previewCallback = (IntPtr frame, IntPtr userData) => { _preview?.Invoke(this, new PreviewEventArgs(new PreviewFrame(frame))); }; CameraErrorFactory.ThrowIfError(Native.SetPreviewCallback(_handle, _previewCallback, IntPtr.Zero), "Setting preview callback failed"); }
/// <summary> /// Stops capturing and drawing preview frames on the screen. /// The camera must be in the <see cref="CameraState.Preview"/> state. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege> /// http://tizen.org/privilege/camera /// </privilege> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception> public void StopPreview() { ValidateState(CameraState.Preview); CameraErrorFactory.ThrowIfError(Native.StopPreview(_handle), "Failed to stop the camera preview."); SetState(CameraState.Created); }
private void RegisterFocusStateChanged() { _focusStateChangedCallback = (CameraFocusState state, IntPtr userData) => { FocusStateChanged?.Invoke(this, new CameraFocusStateChangedEventArgs(state)); }; CameraErrorFactory.ThrowIfError(Native.SetFocusStateChangedCallback(_handle, _focusStateChangedCallback, IntPtr.Zero), "Setting focus changed callback failed"); }
private void RegisterInterruptedCallback() { _interruptedCallback = (CameraPolicy policy, CameraState previous, CameraState current, IntPtr userData) => { Interrupted?.Invoke(this, new CameraInterruptedEventArgs(policy, previous, current)); }; CameraErrorFactory.ThrowIfError(Native.SetInterruptedCallback(_handle, _interruptedCallback, IntPtr.Zero), "Failed to set interrupt callback"); }
private void RegisterErrorCallback() { _errorCallback = (CameraErrorCode error, CameraState current, IntPtr userData) => { ErrorOccurred?.Invoke(this, new CameraErrorOccurredEventArgs(error, current)); }; CameraErrorFactory.ThrowIfError(Native.SetErrorCallback(_handle, _errorCallback, IntPtr.Zero), "Setting error callback failed"); }
private void RegisterHdrCaptureProgress() { _hdrCaptureProgressCallback = (int percent, IntPtr userData) => { _hdrCaptureProgress?.Invoke(this, new HdrCaptureProgressEventArgs(percent)); }; CameraErrorFactory.ThrowIfError(Native.SetHdrCaptureProgressCallback(_handle, _hdrCaptureProgressCallback, IntPtr.Zero), "Setting Hdr capture progress callback failed"); }
/// <summary> /// Starts capturing of still images. /// EventHandler must be set for capturing using <see cref="Capturing"/> /// and for completed using <see cref="CaptureCompleted"/> before calling this method. /// The camera must be in the <see cref="CameraState.Preview"/> state. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege> /// http://tizen.org/privilege/camera /// </privilege> /// <remarks> /// This function causes the transition of the camera state from capturing to captured /// automatically and the corresponding EventHandlers will be invoked. /// The preview should be restarted by calling the <see cref="StartPreview"/> method after capture is completed. /// </remarks> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception> public void StartCapture() { ValidateState(CameraState.Preview); CameraErrorFactory.ThrowIfError(Native.StartCapture(_handle, _capturingCallback, _captureCompletedCallback, IntPtr.Zero), "Failed to start the camera capture."); SetState(CameraState.Capturing); }
/// <summary> /// Starts capturing and drawing preview frames on the screen. /// The display property must be set using <see cref="Display"/> before using this method. /// If needed set fps <see cref="CameraSettings.PreviewFps"/>, preview resolution /// <see cref="CameraSettings.PreviewResolution"/>, or preview format <see cref="CameraSettings.PreviewPixelFormat"/> /// before using this method. /// The camera must be in the <see cref="CameraState.Created"/> or the <see cref="CameraState.Captured"/> state. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege> /// http://tizen.org/privilege/camera /// </privilege> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception> public void StartPreview() { ValidateState(CameraState.Created, CameraState.Captured); CameraErrorFactory.ThrowIfError(Native.StartPreview(_handle), "Failed to start the camera preview."); // Update by StateChangedCallback can be delayed for dozens of milliseconds. SetState(CameraState.Preview); }
private void RegisterStateChangedCallback() { _stateChangedCallback = (CameraState previous, CameraState current, bool byPolicy, IntPtr _) => { SetState(current); Log.Info(CameraLog.Tag, "Camera state changed " + previous.ToString() + " -> " + current.ToString()); StateChanged?.Invoke(this, new CameraStateChangedEventArgs(previous, current, byPolicy)); }; CameraErrorFactory.ThrowIfError(Native.SetStateChangedCallback(_handle, _stateChangedCallback, IntPtr.Zero), "Setting state changed callback failed"); }
private static void RegisterDeviceStateChangedCallback() { _deviceStateChangedCallback = (CameraDevice device, CameraDeviceState state, IntPtr userData) => { _deviceStateChanged?.Invoke(null, new CameraDeviceStateChangedEventArgs(device, state)); }; CameraErrorFactory.ThrowIfError(Native.SetDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero, out _deviceStateCallbackId), "Failed to set device state changed callback"); Log.Info(CameraLog.Tag, "add callbackId " + _deviceStateCallbackId.ToString()); }
/// <summary> /// Stops face detection. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege> /// http://tizen.org/privilege/camera /// </privilege> /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception> /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception> /// <exception cref="ObjectDisposedException">The camera already has been disposed of.</exception> /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception> public void StopFaceDetection() { if (_faceDetectedCallback == null) { throw new InvalidOperationException("The face detection is not started."); } CameraErrorFactory.ThrowIfError(Native.StopFaceDetection(_handle), "Failed to stop the face detection."); _faceDetectedCallback = null; }
private IList <CameraPixelFormat> GetSupportedPreviewPixelFormats() { List <CameraPixelFormat> previewFormats = new List <CameraPixelFormat>(); NativeCapabilities.PreviewFormatCallback callback = (CameraPixelFormat format, IntPtr userData) => { previewFormats.Add(format); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewPixelFormats(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported preview formats."); return(previewFormats.AsReadOnly()); }
private IList <CameraEffectMode> GetSupportedEffects() { List <CameraEffectMode> effectModes = new List <CameraEffectMode>(); NativeCapabilities.EffectCallback callback = (CameraEffectMode effect, IntPtr userData) => { effectModes.Add(effect); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedEffects(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported camera effects."); return(effectModes.AsReadOnly()); }
private IList <Rotation> GetSupportedStreamRotations() { List <Rotation> streamRotations = new List <Rotation>(); NativeCapabilities.StreamRotationCallback callback = (Rotation streamRotation, IntPtr userData) => { streamRotations.Add(streamRotation); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamRotations(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported camera rotations."); return(streamRotations.AsReadOnly()); }
private IList <CameraFps> GetSupportedPreviewFpsByResolutions(int width, int height) { List <CameraFps> fpsByResolution = new List <CameraFps>(); NativeCapabilities.FpsByResolutionCallback callback = (CameraFps fps, IntPtr userData) => { fpsByResolution.Add(fps); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFpsByResolution(_camera.GetHandle(), width, height, callback, IntPtr.Zero), "Failed to get the supported fps by resolutions."); return(fpsByResolution.AsReadOnly()); }
private IList <CameraFps> GetSupportedPreviewFps() { List <CameraFps> previewFps = new List <CameraFps>(); NativeCapabilities.FpsCallback callback = (CameraFps fps, IntPtr userData) => { previewFps.Add(fps); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPreviewFps(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported camera fps"); return(previewFps.AsReadOnly()); }
private IList <CameraSceneMode> GetSupportedSceneModes() { List <CameraSceneMode> sceneModes = new List <CameraSceneMode>(); NativeCapabilities.SceneModeCallback callback = (CameraSceneMode sceneMode, IntPtr userData) => { sceneModes.Add(sceneMode); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedSceneModes(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported scene modes."); return(sceneModes.AsReadOnly()); }
private IList <Flips> GetSupportedStreamFlips() { List <Flips> streamFlips = new List <Flips>(); NativeCapabilities.StreamFlipCallback callback = (Flips streamFlip, IntPtr userData) => { streamFlips.Add(streamFlip); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedStreamFlips(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported camera flips."); return(streamFlips.AsReadOnly()); }
private IList <CameraPtzType> GetSupportedPtzTypes() { List <CameraPtzType> ptzTypes = new List <CameraPtzType>(); NativeCapabilities.PtzTypeCallback callback = (CameraPtzType ptzType, IntPtr userData) => { ptzTypes.Add(ptzType); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedPtzTypes(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported Ptz types."); return(ptzTypes.AsReadOnly()); }
private IList <Size> GetSupportedCaptureResolutions() { List <Size> cameraResolutions = new List <Size>(); NativeCapabilities.CaptureResolutionCallback callback = (int width, int height, IntPtr userData) => { cameraResolutions.Add(new Size(width, height)); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedCaptureResolutions(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported capture resolutions"); return(cameraResolutions.AsReadOnly()); }
private IList <CameraIsoLevel> GetSupportedIsoLevels() { List <CameraIsoLevel> isoLevels = new List <CameraIsoLevel>(); NativeCapabilities.IsoCallback callback = (CameraIsoLevel iso, IntPtr userData) => { isoLevels.Add(iso); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedIso(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported Iso levels."); return(isoLevels.AsReadOnly()); }
private IList <CameraAutoFocusMode> GetSupportedAutoFocusModes() { List <CameraAutoFocusMode> autoFocusModes = new List <CameraAutoFocusMode>(); NativeCapabilities.AfModeCallback callback = (CameraAutoFocusMode mode, IntPtr userData) => { autoFocusModes.Add(mode); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedAutoFocusModes(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported Auto focus modes."); return(autoFocusModes.AsReadOnly()); }
private IList <CameraWhiteBalance> GetSupportedWhitebalances() { List <CameraWhiteBalance> whitebalances = new List <CameraWhiteBalance>(); NativeCapabilities.WhitebalanceCallback callback = (CameraWhiteBalance whiteBalance, IntPtr userData) => { whitebalances.Add(whiteBalance); return(true); }; CameraErrorFactory.ThrowIfError(NativeCapabilities.SupportedWhitebalance(_camera.GetHandle(), callback, IntPtr.Zero), "Failed to get the supported white balance."); return(whitebalances.AsReadOnly()); }
/// <summary> /// Initializes a new instance of the <see cref="Camera"/> class. /// </summary> /// <feature>http://tizen.org/feature/camera</feature> /// <since_tizen> 3 </since_tizen> /// <param name="device">The camera device to access.</param> public Camera(CameraDevice device) { if (!Features.IsSupported(CameraFeatures.Camera)) { throw new NotSupportedException("Camera feature is not supported."); } CameraErrorFactory.ThrowIfError(Native.Create(device, out _handle), "Failed to create camera instance"); Capabilities = new CameraCapabilities(this); Settings = new CameraSettings(this); DisplaySettings = new CameraDisplaySettings(this); RegisterCallbacks(); SetState(CameraState.Created); }