2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Diagnostics;
20 using Native = Interop.Camera;
22 namespace Tizen.Multimedia
25 /// This camera class provides methods to capture photos and supports setting up notifications
26 /// for state changes of capturing, previewing, focusing, and informing about the resolution and the binary format,
27 /// and functions for picture manipulations like sepia, negative, and many more.
28 /// It also notifies you when a significant picture parameter changes, (For example, focus).
30 /// <since_tizen> 3 </since_tizen>
31 /// <feature> http://tizen.org/feature/camera </feature>
32 public partial class Camera : IDisposable, IDisplayable<CameraError>
35 /// Gets or sets the various camera settings.
37 /// <since_tizen> 4 </since_tizen>
38 public CameraSettings Settings { get; internal set; }
41 /// Gets the various camera capabilities.
43 /// <since_tizen> 4 </since_tizen>
44 public CameraCapabilities Capabilities { get; internal set; }
47 /// Get/set various camera display properties.
49 /// <since_tizen> 3 </since_tizen>
50 public CameraDisplaySettings DisplaySettings { get; internal set; }
52 private Display _display;
54 private CameraError SetDisplay(Display display)
58 return CameraDisplay.SetDisplay(GetHandle(), DisplayType.None, IntPtr.Zero);
61 return display.ApplyTo(this);
64 private void ReplaceDisplay(Display newDisplay)
66 _display?.SetOwner(null);
67 _display = newDisplay;
68 _display?.SetOwner(this);
72 /// Sets or gets the display type and handle to show preview images.
73 /// The camera must be in the <see cref="CameraState.Created"/> state.
75 /// <since_tizen> 3 </since_tizen>
77 /// This must be set before the StartPreview() method.
78 /// In custom ROI display mode, DisplayRoiArea property must be set before calling this method.
80 /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
81 /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
82 /// <exception cref="ObjectDisposedException" > The camera has already been disposed. </exception>
83 /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
84 public Display Display
93 ValidateState(CameraState.Created);
95 if (value?.Owner != null)
97 if (ReferenceEquals(this, value.Owner))
102 throw new ArgumentException("The display has already been assigned to another.");
105 SetDisplay(value).ThrowIfFailed("Failed to set the camera display");
107 ReplaceDisplay(value);
111 CameraError IDisplayable<CameraError>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
113 Debug.Assert(_disposed == false);
114 ValidationUtil.ValidateEnum(typeof(DisplayType), type, nameof(type));
116 return CameraDisplay.SetDisplay(GetHandle(), type, evasObject);
119 CameraError IDisplayable<CameraError>.ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation)
121 Debug.Assert(_disposed == false);
123 return CameraDisplay.SetEcoreDisplay(GetHandle(), windowHandle);
127 /// Gets the state of the camera.
129 /// <since_tizen> 3 </since_tizen>
130 /// <value> None, Created, Preview, Capturing, Captured.</value>
131 /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
132 public CameraState State
136 ValidateNotDisposed();
138 Native.GetState(_handle, out CameraState val).ThrowIfFailed("Failed to get camera state");
145 /// The hint for the display reuse.
146 /// If the hint is set to true, the display will be reused when the camera device is changed with
147 /// the ChangeDevice method.
149 /// <since_tizen> 3 </since_tizen>
150 /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
151 /// <exception cref="InvalidOperationException">An invalid state.</exception>
152 /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
153 public bool DisplayReuseHint
157 ValidateNotDisposed();
159 Native.GetDisplayReuseHint(_handle, out bool val).ThrowIfFailed("Failed to get camera display reuse hint");
166 ValidateState(CameraState.Preview);
168 Native.SetDisplayReuseHint(_handle, value).ThrowIfFailed("Failed to set display reuse hint.");
173 /// Gets the facing direction of the camera module.
175 /// <since_tizen> 3 </since_tizen>
176 /// <value>A <see cref="CameraFacingDirection"/> that specifies the facing direction of the camera device.</value>
177 /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
178 public CameraFacingDirection Direction
182 ValidateNotDisposed();
184 Native.GetFacingDirection(_handle, out var val).ThrowIfFailed("Failed to get camera direction");
191 /// Gets the camera device count.
193 /// <since_tizen> 3 </since_tizen>
194 /// <value>This returns 2, if the device supports primary and secondary cameras.
195 /// Otherwise 1, if the device only supports primary camera.</value>
196 /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
197 public int CameraCount
201 ValidateNotDisposed();
203 Native.GetDeviceCount(_handle, out int val).ThrowIfFailed("Failed to get camera device count");