public byte[] GetAlignedBytes(out bool didChange) { didChange = false; if (firstTime) { firstTime = false; didChange = true; } int numBytesPerRow; WindowCapture.UpdateCursorInfo(); byte[] bitmapBytes = GetWindowContents(out numBytesPerRow); if (bitmapBytes != null) { if (actualColorBuffer == null || actualColorBuffer.Length != windowWidth * windowHeight * 3) { actualColorBuffer = new byte[windowWidth * windowHeight * 3]; } int actualNumBytesPerRow = windowWidth * 3; int curOffsetInSrc = 0; int curOffsetInRes = 0; for (int y = 0; y < windowHeight; y++) { Buffer.BlockCopy(bitmapBytes, curOffsetInSrc, actualColorBuffer, curOffsetInRes, actualNumBytesPerRow); curOffsetInSrc += numBytesPerRow; curOffsetInRes += actualNumBytesPerRow; } return(actualColorBuffer); } return(null); }
// Use this for initialization public DesktopCapture(int displayNum) { this.displayNum = displayNum; mouseCapture = new WindowCapture(IntPtr.Zero, true, true); Win32Types.RECT screenRect; Win32Funcs.GetScreenRect(out screenRect); DebugDelegate debugDelegate = new DebugDelegate(DebugFunction); IntPtr intptrDelegate = Marshal.GetFunctionPointerForDelegate(debugDelegate); WindowRenderCS.WindowRenderer.SetDebugFunction(intptrDelegate); pluginFunc = ActuallyRenderWindows; renderCallbackPointer = Marshal.GetFunctionPointerForDelegate(pluginFunc); // You can do a try catch here to test if it is supported Texture2D dummyTexture = new Texture2D(10, 10); WindowRenderCS.WindowRenderer.InitDeskDupl(dummyTexture.GetNativeTexturePtr(), displayNum); desktopTexture = new Texture2D(screenRect.Width, screenRect.Height, TextureFormat.ARGB32, false); testPointer = desktopTexture.GetNativeTexturePtr(); getDesktop = true; }
void OnAddWindowFound(System.IntPtr hwnd) { if (!windowCapturers.ContainsKey(hwnd)) { WindowCapture window = new WindowCapture(hwnd, false); windowCapturers[hwnd] = window; if (OnAddWindow != null) { OnAddWindow(window); } } }