//一定時間ごとにスクショを保存する。 void GetPict() { BITMAP bitmap = DisplayCapt.CaptureWindow(_hwnd); if (bitmap == null) { _exception = new InvalidHandleException(); _isRun = false; return; } if (bitmap.Width != _defBitmap.Width || bitmap.Height != _defBitmap.Height) { _exception = new ChangeSizeException(); _isRun = false; return; } BitmapData bdata = bitmap.Bitmap.LockBits(new Rectangle(0, 0, _defBitmap.Width, _defBitmap.Height), ImageLockMode.ReadOnly, _defBitmap.PixelFormat); byte[] buf = new byte[_defBitmap.Size]; Marshal.Copy(bdata.Scan0, buf, 0, _defBitmap.Size); bitmap.Bitmap.UnlockBits(bdata); _pictureBuf.Add(buf); }
//初期化 void Initialize(PixelFormat pixelFormat) { _defBitmap = DisplayCapt.CaptureWindow(_hwnd); if (_defBitmap == null) { throw new InvalidHandleException(); } _defBitmap.PixelFormat = pixelFormat; BitmapData bitmapData = _defBitmap.Bitmap.LockBits(new Rectangle(0, 0, _defBitmap.Width, _defBitmap.Height), ImageLockMode.ReadOnly, _defBitmap.PixelFormat); _defBitmap.Stride = bitmapData.Stride; _defBitmap.Size = _defBitmap.Stride * _defBitmap.Height; _defBitmap.Bitmap.UnlockBits(bitmapData); }