アンマネージコードを介してビデオを出力する.NETコントロールがあります。
コントロールクライアントエリア(ビデオフレーム)をキャプチャしたいのですが。
Control.DrawToBitmapメソッドは機能せず、コントロールの背景(灰色)を出力します。
次に、GDIのBitBltを使用しようとしました。
[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
int dwRop // raster operation code
);
private const int SRCCOPY = 0xCC0020;
private void btnSave_Click(object sender, EventArgs e)
{
Graphics graphic = captureBox.CreateGraphics();
Bitmap memImage = new Bitmap(captureBox.Width, captureBox.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, this.captureBox.ClientRectangle.Width,
this.captureBox.ClientRectangle.Height, dc1, 0, 0, SRCCOPY);
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
memImage.Save("capture.bmp", ImageFormat.Bmp);
}
それは機能しますが、問題は、キャプチャされたコントロールを超えているコントロールも含めて、すべてをキャプチャすることです。
重なっている場合でもコントロールクライアントエリアをキャプチャしたい。どうすればそれを達成できますか?