EDN Admin
Well-known member
<h1 style="padding:0px; border:0px; font-size:23px; vertical-align:baseline; font-family:Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif; line-height:1.3
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
We are trying to develop a solution where a Desktop screen from a Windows XP machine needs to be monitored remotely.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
From our experience, we have identified that GDI based approach is faster than that of DirectX front buffer capture.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
In GDI we are getting the handle to the screen as follows.
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif // Get the Desktop windows handle and device context
hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);
// Get the handle to the existing DC and create a bitmap file object
HDC hBmpFileDC=CreateCompatibleDC(hDesktopDC);
HBITMAP hBmpFileBitmap=CreateCompatibleBitmap(hDesktopDC,nWidth,nHeight);
// Assign the object in Memory DC to the bitmap and perform a bitblt
SelectObject(hBmpFileDC,hBmpFileBitmap);
BitBlt(hBmpFileDC,0,0,nWidth,nHeight,hDesktopDC,0,0,SRCCOPY|CAPTUREBLT);
// Assign the bitmap handle to a CImage Object
CImage m_temp;
m_temp.Attach(hBmpFileBitmap);
m_temp.Save("d:\Images\Image10.bmp");
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
This operation saves the m_temp CImage object on the hard drive at the given path which means that this object actually holds the data from the screen. But in my application, I want to process the images in the desktop buffer for which I need to have the image
data buffer pointer. But when I call function m_temp.GetBits() which is suppsoed to return the pointer of the data , I get NULL pointer there. (I can see the m_temp holding the correct height, width, bits/pixel data valiues but the image data buffer pointer
is NULL)
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
Even the functions like
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif BITMAP bitmap;
GetObject(hBmpFileBitmap, sizeof(BITMAP), &bitmap);
BYTE *pucInputImage = (BYTE*) bitmap.bmBits; -> Returns NULL
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
Or
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif BYTE* pucImage = NULL;
GetBitmapBits(hBmpFileBitmap,nWidth*nHeight*4,(LPVOID)pucImage);
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
also return NULL in variable pucImage. The only thing which is working is
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif pBuf=malloc(bmpInfo.bmiHeader.biSizeImage)
GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS);
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
Here we need to pass the pBuf variable(preallocated with the size of the Image) and GetDIBits copies the data from the bitmpa handle into this pBuf buffer. This is taking 15 ms extra.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
As far as I Know there is data transfer happeing during bitblt operation and somehow I feel that I should be able to get away with this extra data transfer avoiding 15ms delay per frame.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
One more thing that comes to my mind is because the desktop window needs to be write protected from the user and the HDC hBmpFileDC is derived from the DesktopDC, It might be inheriting the write protection property of the original DC. If this is the case,
is there some way to mark this write protection off for the newly created variables (shown below)
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif HDC hBmpFileDC=CreateCompatibleDC(hDesktopDC);
HBITMAP hBmpFileBitmap=CreateCompatibleBitmap(hDesktopDC,nWidth,nHeight);[/code][/code]
</h1>
View the full article
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
We are trying to develop a solution where a Desktop screen from a Windows XP machine needs to be monitored remotely.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
From our experience, we have identified that GDI based approach is faster than that of DirectX front buffer capture.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
In GDI we are getting the handle to the screen as follows.
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif // Get the Desktop windows handle and device context
hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);
// Get the handle to the existing DC and create a bitmap file object
HDC hBmpFileDC=CreateCompatibleDC(hDesktopDC);
HBITMAP hBmpFileBitmap=CreateCompatibleBitmap(hDesktopDC,nWidth,nHeight);
// Assign the object in Memory DC to the bitmap and perform a bitblt
SelectObject(hBmpFileDC,hBmpFileBitmap);
BitBlt(hBmpFileDC,0,0,nWidth,nHeight,hDesktopDC,0,0,SRCCOPY|CAPTUREBLT);
// Assign the bitmap handle to a CImage Object
CImage m_temp;
m_temp.Attach(hBmpFileBitmap);
m_temp.Save("d:\Images\Image10.bmp");
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
This operation saves the m_temp CImage object on the hard drive at the given path which means that this object actually holds the data from the screen. But in my application, I want to process the images in the desktop buffer for which I need to have the image
data buffer pointer. But when I call function m_temp.GetBits() which is suppsoed to return the pointer of the data , I get NULL pointer there. (I can see the m_temp holding the correct height, width, bits/pixel data valiues but the image data buffer pointer
is NULL)
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
Even the functions like
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif BITMAP bitmap;
GetObject(hBmpFileBitmap, sizeof(BITMAP), &bitmap);
BYTE *pucInputImage = (BYTE*) bitmap.bmBits; -> Returns NULL
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
Or
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif BYTE* pucImage = NULL;
GetBitmapBits(hBmpFileBitmap,nWidth*nHeight*4,(LPVOID)pucImage);
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
also return NULL in variable pucImage. The only thing which is working is
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif pBuf=malloc(bmpInfo.bmiHeader.biSizeImage)
GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS);
[/code][/code]
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
Here we need to pass the pBuf variable(preallocated with the size of the Image) and GetDIBits copies the data from the bitmpa handle into this pBuf buffer. This is taking 15 ms extra.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
As far as I Know there is data transfer happeing during bitblt operation and somehow I feel that I should be able to get away with this extra data transfer avoiding 15ms delay per frame.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
One more thing that comes to my mind is because the desktop window needs to be write protected from the user and the HDC hBmpFileDC is derived from the DesktopDC, It might be inheriting the write protection property of the original DC. If this is the case,
is there some way to mark this write protection off for the newly created variables (shown below)
<pre style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif HDC hBmpFileDC=CreateCompatibleDC(hDesktopDC);
HBITMAP hBmpFileBitmap=CreateCompatibleBitmap(hDesktopDC,nWidth,nHeight);[/code][/code]
</h1>
View the full article