{
try
{
- byte[] tmpBuf = new byte[dataSize];
- Marshal.Copy(thumbData, tmpBuf, 0, dataSize);
-
- tcs.TrySetResult(new ThumbnailExtractionResult(tmpBuf, thumbWidth, thumbHeight));
+ tcs.TrySetResult(new ThumbnailExtractionResult(thumbData, thumbWidth, thumbHeight, dataSize));
}
catch (Exception e)
{
- tcs.TrySetException(new InvalidOperationException("[" + error + "] Failed to copy data.", e));
+ tcs.TrySetException(new InvalidOperationException("[" + error + "] Failed to create ThumbnailExtractionResult instance.", e));
}
finally
{
tcs.TrySetCanceled();
});
}
+
+ /// <summary>
+ /// Extracts the thumbnail for the given media with the specified path and size.
+ /// The generated thumbnail will be returned in <see cref="ThumbnailExtractionResult"/>.
+ /// </summary>
+ /// <remarks>
+ /// The size of generated thumbnail will be 320x240.<br/>
+ /// If you want to set the size of generated thumbnail, please use <see cref="Extract(string, Size)"/><br/>
+ /// <br/>
+ /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage. <br/>
+ /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage.
+ /// </remarks>
+ /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
+ /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
+ /// <param name="path">The path of the media file to extract the thumbnail.</param>
+ /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
+ /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exist.</exception>
+ /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
+ /// <exception cref="FileFormatException">The specified file is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
+ /// <returns>The result of extracting operation.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ public static ThumbnailExtractionResult Extract(string path)
+ {
+ return Extract(path, new Size(320, 240));
+ }
+
+ /// <summary>
+ /// Extracts the thumbnail for the given media with the specified path and size.
+ /// The generated thumbnail will be returned in <see cref="ThumbnailExtractionResult"/>.
+ /// </summary>
+ /// <remarks>
+ /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage. <br/>
+ /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage.
+ /// </remarks>
+ /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
+ /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
+ /// <param name="path">The path of the media file to extract the thumbnail.</param>
+ /// <param name="size">The size of the thumbnail.</param>
+ /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
+ /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exist.</exception>
+ /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">
+ /// The width or the height of <paramref name="size"/> is less than or equal to zero.
+ /// </exception>
+ /// <exception cref="FileFormatException">The specified file is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
+ /// <returns>The result of extracting operation.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ public static ThumbnailExtractionResult Extract(string path, Size size)
+ {
+ if (path == null)
+ {
+ throw new ArgumentNullException(nameof(path));
+ }
+
+ if (File.Exists(path) == false)
+ {
+ throw new FileNotFoundException("File does not exists.", path);
+ }
+
+ if (size.Width <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(size), size.Width,
+ "The width must be greater than zero.");
+ }
+
+ if (size.Height <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(size), size.Height,
+ "The height must be greater than zero.");
+ }
+
+ Native.ExtractToBuffer(path, (uint)size.Width, (uint)size.Height, out IntPtr thumbData,
+ out int dataSize, out uint thumbWidth, out uint thumbHeight).
+ ThrowIfError("Failed to extract thumbnail to buffer");
+
+ try
+ {
+ return new ThumbnailExtractionResult(thumbData, (int)thumbWidth, (int)thumbHeight,
+ dataSize);
+ }
+ finally
+ {
+ if (thumbData != IntPtr.Zero)
+ {
+ LibcSupport.Free(thumbData);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Extracts the thumbnail for the given media with the specified path and size.
+ /// The generated thumbnail will be saved in <paramref name="resultThumbnailPath"/>.
+ /// </summary>
+ /// <remarks>
+ /// The size of generated thumbnail will be 320x240.<br/>
+ /// If you want to set the size of generated thumbnail, please use <see cref="Extract(string, Size, string)"/><br/>
+ /// <br/>
+ /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage. <br/>
+ /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage.
+ /// </remarks>
+ /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
+ /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
+ /// <param name="path">The path of the media file to extract the thumbnail.</param>
+ /// <param name="resultThumbnailPath">The path to save the generated thumbnail.</param>
+ /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
+ /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exist.</exception>
+ /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
+ /// <exception cref="FileFormatException">The specified file is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
+ /// <since_tizen> 6 </since_tizen>
+ public static void Extract(string path, string resultThumbnailPath)
+ {
+ Extract(path, new Size(320, 240), resultThumbnailPath);
+ }
+
+ /// <summary>
+ /// Extracts the thumbnail for the given media with the specified path and size.
+ /// The generated thumbnail will be saved in <paramref name="resultThumbnailPath"/>.
+ /// </summary>
+ /// <remarks>
+ /// If you want to access internal storage, you should add privilege http://tizen.org/privilege/mediastorage. <br/>
+ /// If you want to access external storage, you should add privilege http://tizen.org/privilege/externalstorage.
+ /// </remarks>
+ /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
+ /// <privilege>http://tizen.org/privilege/externalstorage</privilege>
+ /// <param name="path">The path of the media file to extract the thumbnail.</param>
+ /// <param name="size">The size of the thumbnail.</param>
+ /// <param name="resultThumbnailPath">The path to save the generated thumbnail.</param>
+ /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
+ /// <exception cref="FileNotFoundException"><paramref name="path"/> does not exist.</exception>
+ /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
+ /// <exception cref="ArgumentOutOfRangeException">
+ /// The width or the height of <paramref name="size"/> is less than or equal to zero.
+ /// </exception>
+ /// <exception cref="FileFormatException">The specified file is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
+ /// <since_tizen> 6 </since_tizen>
+ public static void Extract(string path, Size size, string resultThumbnailPath)
+ {
+ if (path == null)
+ {
+ throw new ArgumentNullException(nameof(path));
+ }
+
+ if (File.Exists(path) == false)
+ {
+ throw new FileNotFoundException("File does not exists.", path);
+ }
+
+ if (size.Width <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(size), size.Width,
+ "The width must be greater than zero.");
+ }
+
+ if (size.Height <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(size), size.Height,
+ "The height must be greater than zero.");
+ }
+
+ Native.ExtractToFile(path, (uint)size.Width, (uint)size.Height, resultThumbnailPath).
+ ThrowIfError("Failed to extract thumbnail to file.");
+ }
}
}