public override void TakeScreenshot(string output, int width, int height) { using (Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono), tempSurface = device.CreateOffscreenPlainSurface(width, height, Format.X8R8G8B8, Pool.SystemMemory)) { // For DX 8 use IDirect3DDevice8::CreateImageSurface device.GetRenderTargetData(backbuffer, tempSurface); LockedRectangle rect = tempSurface.LockRectangle(LockFlags.ReadOnly | LockFlags.NoDirtyUpdate); using (Bitmap bmp = new Bitmap(width, height, width * sizeof(int), PixelFormat.Format32bppRgb, rect.DataPointer)) { bmp.Save(output, ImageFormat.Png); } tempSurface.UnlockRectangle(); } }
public override void TakeScreenshot(Stream output, int width, int height) { IntPtr backbuffer = Device.GetBackBuffer(device, 0, 0, BackBufferType.Mono); IntPtr temp = Device.CreateOffscreenPlainSurface(device, width, height, Format.X8R8G8B8, Pool.SystemMemory); // For DX 8 use IDirect3DDevice8::CreateImageSurface Device.GetRenderTargetData(device, backbuffer, temp); LockedRectangle rect = Surface.LockRectangle(temp, LockFlags.ReadOnly | LockFlags.NoDirtyUpdate); using (Bitmap bmp = new Bitmap(width, height, width * sizeof(int), PixelFormat.Format32bppRgb, rect.DataPointer)) { Platform.WriteBmp(bmp, output); } Surface.UnlockRectangle(temp); Delete(ref backbuffer); Delete(ref temp); }
/// <summary> /// Locks a rectangle on a surface. /// </summary> /// <param name="flags">The type of lock to perform.</param> /// <returns>A pointer to the locked region</returns> public DataRectangle LockRect(LockFlags flags) { LockedRectangle lockedRect = LockRect(null, flags); return(new DataRectangle(lockedRect.Bits, lockedRect.Pitch)); }
LockRect(out LockedRectangle lockedRect, new IntPtr(&rawRect), flags);