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;
using Tango.RemoteDesktop.Frames;
namespace Tango.RemoteDesktop
{
///
/// Represents an image frame base class.
///
///
public abstract class Frame : IFrame
{
///
/// Gets the frame width.
///
public abstract int Width { get; }
///
/// Gets the frame height.
///
public abstract int Height { get; }
///
/// Returns a GDI bitmap representing the frame.
///
///
public abstract Bitmap ToBitmap();
///
/// Applies this frame onto an existing bitmap.
///
/// The bitmap.
public virtual void Apply(Bitmap bitmap)
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(ToBitmap(), new Rectangle(0, 0, bitmap.Width, bitmap.Height));
}
}
///
/// Applies this frame onto an existing raster frame.
///
/// The frame.
public virtual void Apply(RasterFrame frame)
{
Apply(frame.ToBitmap());
}
///
/// Returns a WPF BitmapSource representing the frame.
///
///
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;
}
///
/// Returns an instance of ready to encode this frame.
///
///
///
public T ToEncoder() where T : IFrameEncoder
{
return (T)Activator.CreateInstance(typeof(T), new object[] { this });
}
///
/// Releases unmanaged and - optionally - managed resources.
///
public abstract void Dispose();
}
}