/// <summary> /// Encodes a specified image with a specified encoder into the current encoded image. /// </summary> /// <param name="image">The image to encode.</param> /// <param name="imageEncoder">The image encoder to use.</param> /// <remarks>The image width, height and pixel format must match. The method should not be called concurrently.</remarks> public void EncodeFrom(Image image, IImageToStreamEncoder imageEncoder) { if (image.Width != this.Width || image.Height != this.Height || image.PixelFormat != this.PixelFormat) { throw new InvalidOperationException("Cannot encode from an image that has a different width, height, or pixel format."); } this.stream.Position = 0; imageEncoder.EncodeToStream(image, this.stream); }
/// <summary> /// Encodes a specified image with a specified encoder into the current encoded image. /// </summary> /// <param name="image">The image to encode.</param> /// <param name="imageEncoder">The image encoder to use.</param> /// <remarks>The image width, height and pixel format must match. The method should not be called concurrently.</remarks> public void EncodeFrom(Image image, IImageToStreamEncoder imageEncoder) { if (image.Width != this.Width || image.Height != this.Height || image.PixelFormat != this.PixelFormat) { throw new InvalidOperationException("Cannot encode from an image that has a different width, height, or pixel format."); } // reset the underlying MemoryStream - this also resets Position to 0 this.stream.SetLength(0); imageEncoder.EncodeToStream(image, this.stream); }