Is there a way to capture the contents of a window -- say, an HTMLView gadget -- into a pixmap? I'd like to capture the contents and put them on a texture.
Capture window contents?
BlitzMax Forums/BlitzMax GUI Programming/Capture window contents? I am pretty interested on this one also... however I have no idea how to do it in blitzmax.
PLS
PLS
d:bug released this excellent module that provides additional desktop functions. This should allow you to (on Windows only at the mo, I think) grab the entire desktop into a pixmap, where you can separate out the window you are after.
That is not what I am after: I want to grab a HTMLview gadget content into a pixmap (i.e. and use what I grab later on on a canvas).
PLS
PLS
I tried grabbing directly from the htmlview gadget, but i only got black & white? so this grabs from the screen (similar to the module mentioned earlier) but limits the grab to just the gadget.
It only does 24 and 32 bits, and is Win32 only.
It only does 24 and 32 bits, and is Win32 only.
Function GrabGadgetPixmap:TPixmap( gadget:TGadget) ?Win32 Extern "Win32" Function GetDIBits:Int( hdc:Int,hbmp:Int,uStartScan:Int,cScanLines:Int,lpvBits:Byte Ptr,lpbmi:Byte Ptr,uUsage:Int) Function CreateDC:Int( driver$z, device$z, output$z, initdata:Byte Ptr) = "CreateDCA@16" EndExtern Function WindowClientToScreen:Int[]( hwnd:Int, screendc:Int) Local client:Int[4], pt1:Int[2], pt2:Int[4] GetClientRect( hwnd, client) pt1[0] = client[RECT_LEFT] pt1[1] = client[RECT_TOP] pt2[0] = client[RECT_RIGHT] pt2[1] = client[RECT_BOTTOM] ClientToScreen( hwnd, pt1) ClientToScreen( hwnd, pt2) Local nx:Int = pt1[0] Local ny:Int = pt1[1] Local nx2:Int = pt2[0] Local ny2:Int = pt2[1] Local scrx:Int = GetDeviceCaps( screendc, HORZRES) Local scry:Int = GetDeviceCaps( screendc, VERTRES) If nx < 0 Then nx = 0 If ny < 0 Then ny = 0 If nx2 > scrx Then nx2 = scrx If ny2 > scry Then ny2 = scry Return [nx,ny, nx2 - nx,ny2 - ny] EndFunction Local hwnd:Int = gadget.Query(QUERY_HWND_CLIENT) Local srcdc:Int = CreateDC( "DISPLAY", Null, Null, Null) Local memdc:Int = CreateCompatibleDC(srcdc) Local rect:Int[] = WindowClientToScreen( hwnd, srcdc) Local bmp:Int = CreateCompatibleBitmap( srcdc, rect[2],rect[3]) Local oldbmp:Int = SelectObject( memdc, bmp) BitBlt( memdc, 0,0,rect[2],rect[3], srcdc,rect[0],rect[1], ROP_SRCCOPY) bmp = SelectObject( memdc, oldbmp) Local pixmap:TPixmap, bits:Int = GetDeviceCaps( srcdc, BITSPIXEL) Select bits ' Case 8 pixmap = CreatePixmap( recr[2],rect[3], PF_I8) ' Case 16 pixmap = CreatePixmap( recr[2],rect[3], PF_BGR888) Case 24 pixmap = CreatePixmap( rect[2],rect[3], PF_BGR888) Case 32 pixmap = CreatePixmap( rect[2],rect[3], PF_BGRA8888) Default Throw "GrabGadgetPixmap() supports only 24 and 32 bits" EndSelect Local bmphdr:BITMAPINFOHEADER = New BITMAPINFOHEADER bmphdr.biSIze = SizeOf(bmphdr) bmphdr.biWidth = pixmap.width bmphdr.biHeight = -pixmap.height bmphdr.biPlanes = 1 bmphdr.biBitCount = bits bmphdr.biCompression = BI_RGB Local p:Byte Ptr = pixmap.pixels For Local y:Int = 0 Until pixmap.height GetDIBits( memdc,bmp, pixmap.height - y - 1,1, p, bmphdr, DIB_RGB_COLORS) p :+ pixmap.pitch Next DeleteObject(bmp) DeleteDC(srcdc) DeleteDC(memdc) Return pixmap ? EndFunction
Thanks Grable!
Anyone knows of a multi-platform way of doing this? Or a Mac specific way that could be used as an alternative for the platform?
PLS
Anyone knows of a multi-platform way of doing this? Or a Mac specific way that could be used as an alternative for the platform?
PLS