blob: a1413d9c909106152c639186f2a7195afa735de9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.RemoteDesktop
{
/// <summary>
/// Represents a base <see cref="IFrameEncoder"/>.
/// </summary>
/// <seealso cref="Tango.RemoteDesktop.IFrameEncoder" />
public abstract class FrameEncoder : IFrameEncoder
{
/// <summary>
/// Gets the frame instance.
/// </summary>
public IFrame Frame { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="FrameEncoder"/> class using an existing <see cref="IFrame"/>.
/// </summary>
/// <param name="frame">The frame.</param>
public FrameEncoder(IFrame frame)
{
Frame = frame;
}
/// <summary>
/// Returns a stream containing the encoded frame.
/// </summary>
/// <returns></returns>
public abstract MemoryStream ToStream();
/// <summary>
/// Returns a byte array containing the encoded frame.
/// </summary>
/// <returns></returns>
public byte[] ToArray()
{
using (var ms = ToStream())
{
return ms.ToArray();
}
}
/// <summary>
/// Gets the image encoder by the specified image format.
/// </summary>
/// <param name="format">The format.</param>
/// <returns></returns>
protected ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
return codecs.Single(codec => codec.FormatID == format.Guid);
}
}
}
|