Added Ambilight-Example-Project

This commit is contained in:
DarthAffe committed 2016-11-06 00:32:40 +01:00
1 parent 662085a346
commit 74824e3363
33 files changed
+1609

No files matched your search

@@ -0,0 +1,64 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Media;
using SharpDX;
using SharpDX.Direct3D9;
namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing
{
public class DX9ScreenCapture : IScreenCapture
{
#region Properties & Fields
private Device _device;
private Surface _surface;
private byte[] _buffer;
public int Width { get; }
public int Height { get; }
public PixelFormat PixelFormat => PixelFormats.Bgr24;
#endregion
#region Constructors
public DX9ScreenCapture()
{
Width = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
Height = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
PresentParameters presentParams = new PresentParameters(Width, Height)
{
Windowed = true,
SwapEffect = SwapEffect.Discard
};
_device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, presentParams);
_surface = Surface.CreateOffscreenPlain(_device, Width, Height, Format.A8R8G8B8, Pool.Scratch);
_buffer = new byte[Width * Height * 4];
}
#endregion
#region Methods
public byte[] CaptureScreen()
{
_device.GetFrontBufferData(0, _surface);
DataRectangle dr = _surface.LockRectangle(LockFlags.None);
Marshal.Copy(dr.DataPointer, _buffer, 0, _buffer.Length);
_surface.UnlockRectangle();
return _buffer;
}
public void Dispose()
{
_device?.Dispose();
_surface?.Dispose();
}
#endregion
}
}
@@ -0,0 +1,18 @@
using System;
using System.Windows.Media;
namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing
{
public interface IScreenCapture : IDisposable
{
int Width { get; }
int Height { get; }
PixelFormat PixelFormat { get; }
/// <summary>
/// As Pixel-Data BGRA
/// </summary>
/// <returns>The Pixel-Data</returns>
byte[] CaptureScreen();
}
}