비트 맵 표현을 가져 오려는 WinForm에 창이 있습니다. 이 캡처시에 창에 깜빡 일 경우캐럿없이 비트 맵에 WinForm 창을 캡쳐하는 방법
public Bitmap GetBitmap()
{
IntPtr srcDC = NativeMethods.GetDC(codeEditor.Handle) ;
var bitmap = new Bitmap(codeEditor.Width, codeEditor.Height) ;
Graphics graphics = Graphics.FromImage(bitmap) ;
var deviceContext = graphics.GetHdc() ;
bool blitted = NativeMethods.BitBlt(
deviceContext,
0,
0,
bitmap.Width,
bitmap.Height,
srcDC,
0,
0,
0x00CC0020 /*SRCCOPY*/) ;
if (!blitted)
{
throw new InvalidOperationException(
@"The bitmap could not be generated.") ;
}
int result = NativeMethods.ReleaseDC(codeEditor.Handle, srcDC) ;
if (result == 0)
{
throw new InvalidOperationException(@"Cannot release bitmap resources.") ;
}
graphics.ReleaseHdc(deviceContext) ;
graphics.Dispose() ;
의 문제점은, 이것은 캐럿을 캡처 :이를 위해 , 나는 (codeEditor
내가의 비트 맵 표현을 원하는 컨트롤입니다) 다음 코드를 사용합니다. 캡처하기 전에 Win32 메서드 HideCaret
을 호출 해 보았습니다. 그러나 어떤 효과도없는 것 같습니다.
여기에 C# 태그가 필요합니다. – MusiGenesis