In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The knowledge of this article "how to use QT+OpenCV to achieve screencap function" is not understood by most people, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use QT+OpenCV to achieve screencap function" article.
(1) get the form interface
The QScreen class has a grabWindow function that can be used to get a picture of the form, which is easy to use by passing in the form handle and the coordinates to be intercepted. But this function has a drawback, it is by intercepting the desktop screen, rather than through the
Form to get the interface, so when your form is obscured by other forms, you will not be able to intercept the complete form interface, if you want to record the entire desktop screen, then use this function, the following method calls the GDI function to achieve, even if the form is obscured can still get the complete interface, but the form minimized also can not be obtained.
/ * * function function: get the image of the specified form * Parameter: hd: form handle * pm: save the acquired picture * x: the starting x coordinate of the intercept, * y: the initial y coordinate of the interception * w: intercepted width * h: intercepted height * / bool GetGDIBitmap (HWND hd,QPixmap & pm, int x, int y, int w, int h) {if (hd==NULL) return false HDC hDC; hDC=GetDCEx (hd,NULL,DCX_PARENTCLIP); HDC hMemDC; / / memory buffer device environment HBITMAP hbmMem,hbmOld; / / Bitmap RECT rc; rc.left=x; rc.top=y; rc.right=x+w; rc.bottom=y+h; / / judgment boundary value RECT clientrc;:: GetClientRect (hd,&clientrc); int xc = 0 Int cx = 0; int cy = 0; if (rc.bottom > clientrc.bottom | | rc.bottomclientrc.right | | rc.rightbiSize = sizeof (BITMAPINFOHEADER); pInfo_Header- > biWidth = rc.right-rc.left; pInfo_Header- > biHeight = (rc.bottom-rc.top); pInfo_Header- > biPlanes = 1; pInfo_Header- > biBitCount = 24; pInfo_Header- > biCompression = BI_RGB; hMemDC=CreateCompatibleDC (hDC) / / create a memory compatible device environment / / create a memory compatible bitmap hbmMem=CreateCompatibleBitmap (hDC,pInfo_Header- > biWidth,pInfo_Header- > biHeight); hbmOld= (HBITMAP) SelectObject (hMemDC,hbmMem); / / draw the contents of the memory device environment to the physical device environment hDC BitBlt (hMemDC,0,0,pInfo_Header- > biWidth,pInfo_Header- > biHeight,hDC,cx+rc.left,xc+cy+rc.top,CAPTUREBLT | SRCCOPY); HBITMAP hBitmap= (HBITMAP) SelectObject (hMemDC,hbmOld) / / get data buf DWORD bufSize= (pInfo_Header- > biWidth * 3 + 3) / 4 * 4 * pInfo_Header- > biHeight; BYTE * pBuffer = new BYTE [bufSize]; int aHeight=pInfo_Header- > biHeight; if (: GetDIBits (hMemDC, hBitmap, 0, aHeight, pBuffer,pBITMAPINFO, DIB_RGB_COLORS) = = 0) {return false;} bool bret=BitmapToPixmap (hBitmap,pm); ReleaseDC (hd,hDC) / / release resource DeleteObject (hbmMem); DeleteObject (hbmOld); DeleteDC (hMemDC); free (pBITMAPINFO);: DeleteObject (hBitmap); delete [] pBuffer; return bret;} / * * function: convert bitmap to QPixmap*/bool BitmapToPixmap (HBITMAP hBitmap, QPixmap & pm) {HDC hDC; / / device description table int iBits / / Bytes per pixel at current display resolution WORD wBitCount; / / Bytes per pixel in bitmap / / define color palette size, pixel byte size in bitmap, bitmap file size, number of bytes written to file DWORD dwPaletteSize=0,dwBmBitsSize,dwDIBSize; BITMAP Bitmap; / / bitmap attribute structure BITMAPFILEHEADER bmfHdr / / Bitmap file header structure BITMAPINFOHEADER bi; / / Bitmap information header structure LPBITMAPINFOHEADER lpbi; / / points to bitmap information header structure HANDLE hDib, hPal; HPALETTE hOldPal=NULL; / / definition file, allocates memory handle, palette handle / / calculates the number of bytes per pixel in a bitmap file hDC = CreateDC (L "DISPLAY", NULL,NULL,NULL) IBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES); DeleteDC (hDC); if (iBits)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.