aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.RemoteDesktop/Frame.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.RemoteDesktop/Frame.cs')
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Frame.cs79
1 files changed, 79 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Frame.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Frame.cs
new file mode 100644
index 000000000..93f38bac0
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Frame.cs
@@ -0,0 +1,79 @@
+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;
+using System.Windows.Media.Imaging;
+
+namespace Tango.RemoteDesktop
+{
+ /// <summary>
+ /// Represents an image frame base class.
+ /// </summary>
+ /// <seealso cref="Tango.RemoteDesktop.IFrame" />
+ public abstract class Frame : IFrame
+ {
+ /// <summary>
+ /// Gets the frame width.
+ /// </summary>
+ public abstract int Width { get; }
+
+ /// <summary>
+ /// Gets the frame height.
+ /// </summary>
+ public abstract int Height { get; }
+
+ /// <summary>
+ /// Returns a GDI bitmap representing the frame.
+ /// </summary>
+ /// <returns></returns>
+ public abstract Bitmap ToBitmap();
+
+ /// <summary>
+ /// Applies this frame onto an existing bitmap.
+ /// </summary>
+ /// <param name="bitmap">The bitmap.</param>
+ public virtual void Apply(Bitmap bitmap)
+ {
+ using (Graphics g = Graphics.FromImage(bitmap))
+ {
+ g.DrawImage(ToBitmap(), new Rectangle(0, 0, bitmap.Width, bitmap.Height));
+ }
+ }
+
+ /// <summary>
+ /// Returns a WPF BitmapSource representing the frame.
+ /// </summary>
+ /// <returns></returns>
+ public BitmapSource ToBitmapSource()
+ {
+ MemoryStream ms = new MemoryStream();
+ ToBitmap().Save(ms, ImageFormat.Bmp);
+ ms.Position = 0;
+ var bitmapImage = new BitmapImage();
+ bitmapImage.BeginInit();
+ bitmapImage.StreamSource = ms;
+ bitmapImage.EndInit();
+ bitmapImage.Freeze();
+ return bitmapImage;
+ }
+
+ /// <summary>
+ /// Returns an instance of <see cref="IFrameEncoder" /> ready to encode this frame.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns></returns>
+ public IFrameEncoder ToEncoder<T>() where T : IFrameEncoder
+ {
+ return Activator.CreateInstance(typeof(T), new object[] { this }) as IFrameEncoder;
+ }
+
+ /// <summary>
+ /// Releases unmanaged and - optionally - managed resources.
+ /// </summary>
+ public abstract void Dispose();
+ }
+}