/// <summary> /// Encodes a Graphics Interchange Format (GIF) image from multiple raw image buffers to a specified <see cref="Stream"/>. /// </summary> /// <param name="frames">The image frames to encode.</param> /// <param name="outStream">The stream that the image is encoded to.</param> /// <returns>A task that represents the asynchronous encoding operation.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="frames"/> is null.<br/> /// -or-<br/> /// <paramref name="outStream"/> is null. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="frames"/> has no element(empty).<br/> /// -or-<br/> /// <paramref name="outStream"/> is not writable. /// </exception> /// <exception cref="InvalidOperationException">The resolution is not set.</exception> /// <exception cref="ObjectDisposedException">The <see cref="ImageEncoder"/> has already been disposed of.</exception> /// <seealso cref="ImageEncoder.SetResolution"/> /// <since_tizen> 4 </since_tizen> public Task EncodeAsync(IEnumerable <GifFrame> frames, Stream outStream) { if (frames == null) { throw new ArgumentNullException(nameof(frames)); } if (frames.Count() == 0) { throw new ArgumentException("frames is a empty collection", nameof(frames)); } return(EncodeAsync(handle => { foreach (GifFrame frame in frames) { if (frame == null) { throw new ArgumentNullException(nameof(frames)); } Unmanaged.SetInputBuffer(handle, frame.Buffer). ThrowIfFailed("Failed to configure encoder; Buffer"); Unmanaged.SetGifFrameDelayTime(handle, (ulong)frame.Delay). ThrowIfFailed("Failed to configure encoder; Delay"); } }, outStream)); }
/// <summary> /// Encodes an image from a raw image buffer to a specified <see cref="Stream"/>. /// </summary> /// <param name="inputBuffer">The image buffer to encode.</param> /// <param name="outStream">The stream that the image is encoded to.</param> /// <returns>A task that represents the asynchronous encoding operation.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="inputBuffer"/> is null.<br/> /// -or-<br/> /// <paramref name="outStream"/> is null. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="inputBuffer"/> is an empty array.<br/> /// -or-<br/> /// <paramref name="outStream"/> is not writable. /// </exception> /// <exception cref="InvalidOperationException">The resolution is not set.</exception> /// <exception cref="ObjectDisposedException">The <see cref="ImageEncoder"/> has already been disposed of.</exception> /// <seealso cref="SetResolution"/> /// <since_tizen> 4 </since_tizen> public Task EncodeAsync(byte[] inputBuffer, Stream outStream) { if (inputBuffer == null) { throw new ArgumentNullException(nameof(inputBuffer)); } if (inputBuffer.Length == 0) { throw new ArgumentException("buffer is empty.", nameof(inputBuffer)); } return(EncodeAsync(handle => { Unmanaged.SetInputBuffer(handle, inputBuffer). ThrowIfFailed("Failed to configure encoder; InputBuffer"); }, outStream)); }