/
Camera.Properties.cs
209 lines (177 loc) · 7.49 KB
/
Camera.Properties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Diagnostics;
using static Interop;
using Native = Interop.Camera;
namespace Tizen.Multimedia
{
/// <summary>
/// This camera class provides methods to capture photos and supports setting up notifications
/// for state changes of capturing, previewing, focusing, and informing about the resolution and the binary format,
/// and functions for picture manipulations like sepia, negative, and many more.
/// It also notifies you when a significant picture parameter changes, (For example, focus).
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <feature> http://tizen.org/feature/camera </feature>
public partial class Camera : IDisposable, IDisplayable<CameraError>
{
/// <summary>
/// Gets or sets the various camera settings.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public CameraSettings Settings { get; internal set; }
/// <summary>
/// Gets the various camera capabilities.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public CameraCapabilities Capabilities { get; internal set; }
/// <summary>
/// Get/set various camera display properties.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public CameraDisplaySettings DisplaySettings { get; internal set; }
private Display _display;
private CameraError SetDisplay(Display display)
{
if (display == null)
{
return CameraDisplay.SetDisplay(GetHandle(), DisplayType.None, IntPtr.Zero);
}
return display.ApplyTo(this);
}
private void ReplaceDisplay(Display newDisplay)
{
_display?.SetOwner(null);
_display = newDisplay;
_display?.SetOwner(this);
}
/// <summary>
/// Sets or gets the display type and handle to show preview images.
/// The camera must be in the <see cref="CameraState.Created"/> state.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <remarks>
/// This must be set before the StartPreview() method.
/// In custom ROI display mode, DisplayRoiArea property must be set before calling this method.
/// </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 has already been disposed. </exception>
/// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
public Display Display
{
get
{
return _display;
}
set
{
ValidateState(CameraState.Created);
if (value?.Owner != null)
{
if (ReferenceEquals(this, value.Owner))
{
return;
}
throw new ArgumentException("The display has already been assigned to another.");
}
SetDisplay(value).ThrowIfFailed("Failed to set the camera display");
ReplaceDisplay(value);
}
}
CameraError IDisplayable<CameraError>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
{
Debug.Assert(_disposed == false);
ValidationUtil.ValidateEnum(typeof(DisplayType), type, nameof(type));
return CameraDisplay.SetDisplay(GetHandle(), type, evasObject);
}
CameraError IDisplayable<CameraError>.ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation)
{
Debug.Assert(_disposed == false);
return CameraDisplay.SetEcoreDisplay(GetHandle(), windowHandle);
}
/// <summary>
/// Gets the state of the camera.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <value> None, Created, Preview, Capturing, Captured.</value>
/// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
public CameraState State
{
get
{
ValidateNotDisposed();
Native.GetState(_handle, out CameraState val).ThrowIfFailed("Failed to get camera state");
return val;
}
}
/// <summary>
/// The hint for the display reuse.
/// If the hint is set to true, the display will be reused when the camera device is changed with
/// the ChangeDevice method.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <exception cref="ArgumentException">In case of invalid parameters.</exception>
/// <exception cref="InvalidOperationException">An invalid state.</exception>
/// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
public bool DisplayReuseHint
{
get
{
ValidateNotDisposed();
Native.GetDisplayReuseHint(_handle, out bool val).ThrowIfFailed("Failed to get camera display reuse hint");
return val;
}
set
{
ValidateState(CameraState.Preview);
Native.SetDisplayReuseHint(_handle, value).ThrowIfFailed("Failed to set display reuse hint.");
}
}
/// <summary>
/// Gets the facing direction of the camera module.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <value>A <see cref="CameraFacingDirection"/> that specifies the facing direction of the camera device.</value>
/// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
public CameraFacingDirection Direction
{
get
{
ValidateNotDisposed();
Native.GetFacingDirection(_handle, out var val).ThrowIfFailed("Failed to get camera direction");
return val;
}
}
/// <summary>
/// Gets the camera device count.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <value>This returns 2, if the device supports primary and secondary cameras.
/// Otherwise 1, if the device only supports primary camera.</value>
/// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
public int CameraCount
{
get
{
ValidateNotDisposed();
Native.GetDeviceCount(_handle, out int val).ThrowIfFailed("Failed to get camera device count");
return val;
}
}
}
}