diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-02 23:30:34 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-02 23:30:34 +0200 |
| commit | 0dcd742a3c35527386a93e1b1ef761c2aeff8308 (patch) | |
| tree | d5adb3fee35e73af95fa5d68b5316d25522471de /Software/Visual_Studio/Tango.RemoteDesktop/Encoders/JpegEncoder.cs | |
| parent | 1a7fb274158f8a0e279aef26206a65fefac8c4c3 (diff) | |
| download | Tango-0dcd742a3c35527386a93e1b1ef761c2aeff8308.tar.gz Tango-0dcd742a3c35527386a93e1b1ef761c2aeff8308.zip | |
Implemented Tango.RemoteDesktop.
Implemented png 8 bit quantization.
Implemented RasterFrame bounds clipping.
Refactored VectorFrame to use indexed colors.
Diffstat (limited to 'Software/Visual_Studio/Tango.RemoteDesktop/Encoders/JpegEncoder.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.RemoteDesktop/Encoders/JpegEncoder.cs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Encoders/JpegEncoder.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Encoders/JpegEncoder.cs new file mode 100644 index 000000000..744849977 --- /dev/null +++ b/Software/Visual_Studio/Tango.RemoteDesktop/Encoders/JpegEncoder.cs @@ -0,0 +1,68 @@ +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 +{ + /// <summary> + /// Represents an <see cref="IFrame"/> JPEG encoder. + /// </summary> + /// <seealso cref="Tango.RemoteDesktop.FrameEncoder" /> + public class JpegEncoder : FrameEncoder + { + /// <summary> + /// Initializes a new instance of the <see cref="JpegEncoder"/> class. + /// </summary> + /// <param name="frame">The frame.</param> + public JpegEncoder(IFrame frame) : base(frame) + { + } + + /// <summary> + /// Returns a stream containing the encoded frame. + /// </summary> + /// <returns></returns> + public override MemoryStream ToStream() + { + return ToStream(100); + } + + /// <summary> + /// Returns a stream containing the encoded frame with the specified quality. + /// </summary> + /// <param name="quality">The quality.</param> + /// <returns></returns> + 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; + } + + /// <summary> + /// Returns a byte array containing the encoded frame with the specified quality. + /// </summary> + /// <param name="quality">The quality.</param> + /// <returns></returns> + public byte[] ToArray(long quality) + { + using (MemoryStream ms = ToStream(quality)) + { + return ms.ToArray(); + } + } + + private ImageCodecInfo GetEncoder(ImageFormat format) + { + ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders(); + return codecs.Single(codec => codec.FormatID == format.Guid); + } + } +} |
