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.Collections.Generic;
21 using System.Threading.Tasks;
22 using System.Collections.ObjectModel;
23 using System.Runtime.InteropServices;
25 namespace Tizen.Content.MediaContent
28 /// ImageContent class API gives the information related to the image media stored in the device</summary>
29 public class ImageInformation : MediaInformation
31 private readonly Interop.ImageInformation.SafeImageInformationHandle _handle;
34 /// Gets the id of the media.
36 /// <since_tizen> 3 </since_tizen>
41 IntPtr val = IntPtr.Zero;
44 MediaContentValidator.ThrowIfError(
45 Interop.ImageInformation.GetMediaId(_handle, out val), "Failed to get value");
47 return Marshal.PtrToStringAnsi(val);
51 Interop.Libc.Free(val);
57 /// Gets the image width in pixels.
59 /// <since_tizen> 3 </since_tizen>
65 MediaContentValidator.ThrowIfError(
66 Interop.ImageInformation.GetWidth(_handle, out width), "Failed to get value");
73 /// Gets the image height in pixels.
75 /// <since_tizen> 3 </since_tizen>
81 MediaContentValidator.ThrowIfError(
82 Interop.ImageInformation.GetHeight(_handle, out height), "Failed to get value");
89 /// Image orientation.
91 /// <since_tizen> 3 </since_tizen>
92 public MediaContentOrientation Orientation
96 MediaContentOrientation orientation = MediaContentOrientation.NotAvailable;
97 MediaContentValidator.ThrowIfError(
98 Interop.ImageInformation.GetOrientation(_handle, out orientation), "Failed to get value");
105 MediaContentValidator.ThrowIfError(
106 Interop.ImageInformation.SetOrientation(_handle, value), "Failed to set value");
111 /// Gets the image creation time in seconds, since the Epoch.
113 /// <since_tizen> 3 </since_tizen>
114 public string TakenDate
118 IntPtr val = IntPtr.Zero;
121 MediaContentValidator.ThrowIfError(
122 Interop.ImageInformation.GetDateTaken(_handle, out val), "Failed to get value");
124 return Marshal.PtrToStringAnsi(val);
128 Interop.Libc.Free(val);
134 /// Gets the burst shot ID.
135 /// If BurstId is null, this is not a burst shot
137 /// <since_tizen> 3 </since_tizen>
138 public string BurstId
142 IntPtr val = IntPtr.Zero;
145 MediaContentValidator.ThrowIfError(
146 Interop.ImageInformation.GetBurstId(_handle, out val), "Failed to get value");
148 return Marshal.PtrToStringAnsi(val);
152 Interop.Libc.Free(val);
158 /// Gets the exposure time from exif.
160 /// <since_tizen> 3 </since_tizen>
161 public string ExposureTime
165 IntPtr val = IntPtr.Zero;
168 MediaContentValidator.ThrowIfError(
169 Interop.ImageInformation.GetExposureTime(_handle, out val), "Failed to get value");
171 return Marshal.PtrToStringAnsi(val);
175 Interop.Libc.Free(val);
181 /// Gets the fnumber from exif.
183 /// <since_tizen> 3 </since_tizen>
184 public double FNumber
188 double fNumber = 0.0;
189 MediaContentValidator.ThrowIfError(
190 Interop.ImageInformation.GetFNumber(_handle, out fNumber), "Failed to get value");
197 /// Gets the iso from exif.
199 /// <since_tizen> 3 </since_tizen>
205 MediaContentValidator.ThrowIfError(
206 Interop.ImageInformation.GetISO(_handle, out iso), "Failed to get value");
213 /// Gets the model from exif.
215 /// <since_tizen> 3 </since_tizen>
220 IntPtr val = IntPtr.Zero;
223 MediaContentValidator.ThrowIfError(
224 Interop.ImageInformation.GetModel(_handle, out val), "Failed to get value");
226 return Marshal.PtrToStringAnsi(val);
230 Interop.Libc.Free(val);
236 /// Checks whether the media is a burst shot image.
237 /// The value is true if the media is a burst shot image,
238 /// otherwise false if the media is not a burst shot image.
240 /// <since_tizen> 3 </since_tizen>
241 public bool IsBurstShot
245 bool isBurst = false;
246 MediaContentValidator.ThrowIfError(
247 Interop.ImageInformation.IsBurstShot(_handle, out isBurst), "Failed to get value");
254 /// Iterates through the media faces with filter in the given media file from the media database.
255 /// If NULL is passed to the filter, no filtering is applied.
257 /// <since_tizen> 3 </since_tizen>
259 /// Task to get all the MediaFaces </returns>
260 /// <param name="filter"> filter for the Tags</param>
261 public IEnumerable<MediaFace> GetMediaFaces(ContentFilter filter)
263 Collection<MediaFace> coll = new Collection<MediaFace>();
265 Interop.MediaInformation.MediaFaceCallback callback = (IntPtr faceHandle, IntPtr userData) =>
267 IntPtr newHandle = IntPtr.Zero;
268 MediaContentValidator.ThrowIfError(
269 Interop.Face.Clone(out newHandle, faceHandle), "Failed to clone Tag");
271 coll.Add(new MediaFace(newHandle));
274 IntPtr filterHandle = (filter != null) ? filter.Handle : IntPtr.Zero;
275 MediaContentValidator.ThrowIfError(
276 Interop.MediaInformation.GetAllFaces(MediaId, filterHandle, callback, IntPtr.Zero), "Failed to get value");
282 /// Gets the number of faces for the passed filter in the given media ID from the media database.
284 /// <since_tizen> 3 </since_tizen>
286 /// int count</returns>
287 /// <param name="filter">The Filter for matching Face</param>
288 public int GetMediaFaceCount(ContentFilter filter)
291 IntPtr handle = (filter != null) ? filter.Handle : IntPtr.Zero;
292 MediaContentValidator.ThrowIfError(
293 Interop.MediaInformation.GetFaceCount(MediaId, handle, out count), "Failed to get value");
300 /// Inserts a MediaFace item to the media database
302 /// <since_tizen> 3 </since_tizen>
303 /// <param name="image">The image on which face is to be added</param>
304 /// <param name="rect">The dimensions of the face</param>
305 /// <returns>The MediaFace instance</returns>
306 public MediaFace AddFace(ImageInformation image, FaceRect rect)
308 MediaFace face = new MediaFace(image, rect);
309 ContentManager.Database.Insert(face);
314 /// Deletes the MediaFace from the media database.
316 /// <since_tizen> 3 </since_tizen>
317 /// <param name="face">The face instance to be deleted</param>
318 public void DeleteFace(MediaFace face)
320 ContentManager.Database.Delete(face);
324 /// Updates the MediaFace in the media database
326 /// <since_tizen> 3 </since_tizen>
327 /// <param name="face">The MediaFace object to be updated</param>
328 public void UpdateFace(MediaFace face)
330 ContentManager.Database.Update(face);
333 internal IntPtr ImageHandle
337 return _handle.DangerousGetHandle();
341 internal ImageInformation(Interop.ImageInformation.SafeImageInformationHandle handle, Interop.MediaInformation.SafeMediaInformationHandle mediaInformationHandle)
342 : base(mediaInformationHandle)