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.
20 using System.Runtime.InteropServices;
22 namespace Tizen.Content.MediaContent
25 /// The Media Face Information API provides functions to manage the face information in the image files.
27 public class MediaFace : IDisposable
29 private IntPtr _faceHandle = IntPtr.Zero;
30 private bool _disposedValue = false;
31 internal IntPtr Handle
35 if (_faceHandle == IntPtr.Zero)
37 throw new ObjectDisposedException(nameof(MediaFace));
45 internal MediaFace(IntPtr handle)
51 /// Create Face for Given Image
53 /// <since_tizen> 3 </since_tizen>
54 /// <param name="image">
55 ///image item through which FaceRect has to be tagged.
57 ///<param name="rect">Position about the detacted face in the media</param>
58 internal MediaFace(MediaInformation image, FaceRect rect)
60 MediaContentValidator.ThrowIfError(
61 Interop.Face.Create(image.MediaId, out _faceHandle), "Failed to create MediaFace");
65 MediaContentValidator.ThrowIfError(
66 Interop.Face.SetFaceRect(Handle, rect.X, rect.Y, rect.Width, rect.Height), "Failed to set Rect to MediaFace");
70 Interop.Face.Destroy(_faceHandle);
81 /// The Media Face Information API provides functions to manage the face information in the image files.
83 /// <since_tizen> 3 </since_tizen>
92 MediaContentValidator.ThrowIfError(
93 Interop.Face.GetFaceRect(Handle, out x, out y, out width, out height), "Failed to get Rect for the Face");
95 return new FaceRect(x, y, width, height);
100 FaceRect rect = (FaceRect)value;
101 MediaContentValidator.ThrowIfError(
102 Interop.Face.SetFaceRect(Handle, rect.X, rect.Y, rect.Width, rect.Height), "Failed to set Rect for the Face");
109 /// <since_tizen> 3 </since_tizen>
114 IntPtr val = IntPtr.Zero;
117 MediaContentValidator.ThrowIfError(
118 Interop.Face.GetFaceId(Handle, out val), "Failed to get value");
120 return Marshal.PtrToStringAnsi(val);
124 Interop.Libc.Free(val);
130 /// Media uuid from the face
132 /// <since_tizen> 3 </since_tizen>
133 public string MediaInformationId
137 IntPtr val = IntPtr.Zero;
140 MediaContentValidator.ThrowIfError(
141 Interop.Face.GetMediaId(Handle, out val), "Failed to get value");
143 return Marshal.PtrToStringAnsi(val);
147 Interop.Libc.Free(val);
152 /// Tag name for the MediaFace.
154 /// <since_tizen> 3 </since_tizen>
159 IntPtr val = IntPtr.Zero;
162 MediaContentValidator.ThrowIfError(
163 Interop.Face.GetTag(Handle, out val), "Failed to get value");
165 return Marshal.PtrToStringAnsi(val);
169 Interop.Libc.Free(val);
175 MediaContentValidator.ThrowIfError(
176 Interop.Face.SetTag(Handle, value), "Failed to set value");
181 /// Orientation Value for the face
183 /// <since_tizen> 3 </since_tizen>
184 public MediaContentOrientation Orientation
189 MediaContentValidator.ThrowIfError(
190 Interop.Face.GetOrientation(Handle, out orientation), "Failed to value");
192 return (MediaContentOrientation)orientation;
197 MediaContentValidator.ThrowIfError(
198 Interop.Face.SetOrientation(Handle, (int)value), "Failed to set value");
203 /// Dispose API for closing the internal resources.
205 /// <since_tizen> 3 </since_tizen>
206 public void Dispose()
209 GC.SuppressFinalize(this);
212 protected virtual void Dispose(bool disposing)
216 if (_faceHandle != IntPtr.Zero)
218 Interop.Face.Destroy(_faceHandle);
219 _faceHandle = IntPtr.Zero;
222 _disposedValue = true;