c# - Using BitBlt to capture screenshot, how? -


i have run "bitblt" time time in searched, don´t how use it.

from people say, seems fastest way capture screen windows show. however, can´t myself don´t got working.

the thing have manage atleast, try method, this:

 gfxbmp.copyfromscreen(0,0,0,0 rc.size,copypixeloperation.captureblt); 

which guess uses it? (rc.size = size of window) sadly, doesn´t anything, black picture. if use sourcecopy however, works, normal method.

i trying replace code, use bltbit, isn´t working either:

    public memorystream capturewindow(intptr hwnd, encoderparameters jpegparam)     {         nativemethods.rect rc;         nativemethods.getwindowrect(hwnd, out rc);         using (bitmap bmp = new bitmap(rc.width, rc.height, system.drawing.imaging.pixelformat.format32bppargb))         {              using (graphics gfxbmp = graphics.fromimage(bmp))             {                 intptr hdcbitmap = gfxbmp.gethdc();                 try                 {                       nativemethods.bitblt(hdcbitmap, 0, 0, 0, 0, hwnd, 0, 0, 0xcc0020);                  }                                 {                     gfxbmp.releasehdc(hdcbitmap);                 }             }             memorystream ms = new memorystream();             bmp.save(ms, getencoderinfo(imageformat.jpeg), jpegparam);              return ms;         }     } 

you right, graphics.copyfromscreen uses bitblt internally. following, code .net 4.0 framework:

// [...] new uipermission(uipermissionwindow.allwindows).demand(); int width = blockregionsize.width; int height = blockregionsize.height; using (devicecontext devicecontext = devicecontext.fromhwnd(intptr.zero)) {     handleref hsrcdc = new handleref(null, devicecontext.hdc);     handleref hdc = new handleref(null, this.gethdc());     try     {         if (safenativemethods.bitblt(hdc, destinationx, destinationy, width, height, hsrcdc, sourcex, sourcey, (int)copypixeloperation) == 0)         {             throw new win32exception();         }     }         {         this.releasehdc();     } } 

there other possibilities capture screenshots. use winapi function printwindow.

but graphiccard-accelerated content, both won't work. hardware overlay resides in gpu-memory, can't access it. that's why black image videos, games, ...


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -