using System; using System.Collections.Generic; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.RemoteDesktop.Encoders { /// /// Represents an JPEG encoder. /// /// public class JpegEncoder : FrameEncoder { /// /// Initializes a new instance of the class. /// /// The frame. public JpegEncoder(IFrame frame) : base(frame) { } /// /// Returns a stream containing the encoded frame. /// /// public override MemoryStream ToStream() { return ToStream(100); } /// /// Returns a stream containing the encoded frame with the specified quality. /// /// The quality. /// public virtual MemoryStream ToStream(long quality) { var encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); MemoryStream ms = new MemoryStream(); Frame.ToBitmap().Save(ms, GetEncoder(ImageFormat.Jpeg), encoderParameters); ms.Position = 0; return ms; } /// /// Returns a byte array containing the encoded frame with the specified quality. /// /// The quality. /// public byte[] ToArray(long quality) { using (MemoryStream ms = ToStream(quality)) { return ms.ToArray(); } } } }