|
Each time the window refreshes, you have to capture it into a bitmap then compare the bitmap with the last screen capture. So to capture the screen:
HDC hMemDC;
HBITMAP hBitmap;
HBITMAP hBitmapOld;
BITMAPINFO bmi;
LPBYTE data;
int width, int height;
RECT rc;
GetWindowRect( hwnd, &rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
hMemDC = CreateCompatibleDC( hDC );
hBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS, (void**)&data, NULL, NULL );
hBitmapOld = (HBITMAP)SelectObject( hMemDC, hBitmap );
if( hBitmap )
{
BitBlt( hMemDC, 0, 0, width, height, hDC, 0, 0, SRCCOPY );
SelectObject( hMemDC, hBitmapOld );
}
At this point your buffer given by "data" will have the pixel contents from the screen. You will need to load the previous bitmap and compare pixels. To load a previous bitmap you can use the LoadBitmap and GetBitmapBits functions.
I hope this helps.
Deus caritas est
|
|
|
|
|
if (st_x >= 0 && st_y >= 0)
if (st_x <= dForme.Width && st_y <= dForme.Height)
//change button position
button2.SetBounds(st_x, st_y, button2.Width, button2.Height);
else
{
textBox2.Text = st_x.ToString();
textBox3.Text = st_y.ToString();
}
visual c++ position of button little code That is a little code for visual c++. That code change position of button.
is that ok ?
-- modified at 11:00 Thursday 11th May, 2006
|
|
|
|
|
|
I think yes
I see Control.SetBounds Method in (.NET Framework Class Library)
|
|
|
|
|
|
I saw one question C# here i think yesterday that of course cedric answer to the qeustion
|
|
|
|
|
xcar wrote: visual c++ position of button little code That is a little code for visual c++. That code change position of button.
Uuhhh . I didn't understand anything. Could you please rephrase your sentence ?
Ans also, post a question .
|
|
|
|
|
|
|
Hi,
i get a 32 bit RGBA Image from my firewire camera...and i want to display a gray scale image to a Picture Control with MFC!
convert function:
<br />
void CImageProcView::RGBA2Gray(char *Img1, char *Img2, unsigned int ByteSize)<br />
{<br />
for(int i = 0; i<ByteSize/4; i++)<br />
{<br />
Img2[i]=((signed char)Img1[4*i]+(signed char)Img1[4*i+1]+(signed char)Img1[4*i+2])/3;<br />
}<br />
}<br />
<br />
char *CurrentImage;<br />
char *GrayMap;<br />
CStatic m_Img1;<br />
CBitmap Bitmap1;<br />
memcpy(Current,FireCapture->FlippedBuffer,FireCapture->grabBufferSize);<br />
<br />
RGBA2Gray(CurrentImage, GrayMap, FireCapture->grabBufferSize);
<br />
Bitmap1.CreateBitmap(FireCapture->pVih->bmiHeader.biWidth, FireCapture->pVih->bmiHeader.biHeight, 1, 8, GrayMap);<br />
<br />
m_Img1.SetBitmap(Bitmap1);<br />
somthing dont work with this CStatic Picture Control;/ any idea? i think the CreateBitmap dont take the cBitsPerPel;/
bye
|
|
|
|
|
Only about the algorithm:
surfman19 wrote: void CImageProcView::RGBA2Gray(char *Img1, char *Img2, unsigned int ByteSize)
{
for(int i = 0; i {
Img2[i]=((signed char)Img1[4*i]+(signed char)Img1[4*i+1]+(signed char)Img1[4*i+2])/3;
}
}
I think that this will generate some overflows, I like more this:
Img2[i]=signed char(((int)Img1[4*i]+(int)Img1[4*i+1]+(int)Img1[4*i+2])/3);
and why signed ? Is it better using unsigned char/int ?
bye
|
|
|
|
|
<br />
the output of the camera is a RGBA32 image!<br />
<br />
CStatic m_Img1;<br />
unsigned char *ActImage;<br />
unsigned char *GrayMap;<br />
<br />
ActImage = new unsigned char[FireCapture->grabBufferSize];<br />
GrayMap = new unsigned char[FireCapture->grabBufferSize];<br />
<br />
memcpy(ActImage,FireCapture->FlippedBuffer,FireCapture->grabBufferSize);<br />
RGB2Gray(ActImage, GrayMap, FireCapture->grabBufferSize);<br />
<br />
Bitmap1.CreateBitmap(FireCapture->pVih->bmiHeader.biWidth, FireCapture->pVih->bmiHeader.biHeight,<br />
1,8,GrayMap);<br />
m_Img1.SetBitmap(Bitmap1);<br />
<br />
<br />
<br />
<br />
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)<br />
{<br />
for(int i = 0; i<ByteSize/4; i++)<br />
{<br />
Img2[i] = ((char)Img1[4*i] + (char)Img1[4*i+1] + (char)Img1[4*i+2]) / 3;<br />
}<br />
}<br />
why could the CStatic dont display the grayscale image????hm;/
cu
|
|
|
|
|
Your loop is already wrong. Img2 is an unsigned char *, so Img2[0] refers to byte 0, Img2[1] refers to byte 1, etc. And you should be creating your bitmap using CreateDIBitmap().
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)
{
for(int i = 0; i<ByteSize/4; i++)
{
Img2[i] = ((char)Img1[4*i] + (char)Img1[4*i+1] + (char)Img1[4*i+2]) / 3;
}
}
If you find it difficult to think in terms of bytes, you can always cast it to RGBQUAD.
void CImageProcView::RGB2Gray(unsigned char *Img1, unsigned char *Img2, unsigned int ByteSize)
{
RGBQUAD *pSource = static_cast<RGBQUAD*>(Img1);
RGBQUAD *pDest = static_cast<RGBQUAD*>(Img2);
for(int i = 0; i<ByteSize/sizeof(RGBQUAD); i++)
{
pDest[i].rgbRed = pDest[i].rgbGreen = pDest[i].rgbBlue = (pSource[i].rgbBlue + pSource[i].rgbGreen + pSource[i].rgbRed) / 3;
pDest[i].rgbReserved = 0;
}
}
|
|
|
|
|
<br />
RGBQUAD *pSource = static_cast(Img1);<br />
static cast need a type to cast!! do you mean static_cast<RGBQUAD>(Img1); ?<br />
<br />
i always get a error C2440: 'static_cast' : cannot convert from 'unsigned char *' to 'RGBQUAD'<br />
your grayscale is now 32 bit right? cant i use 8 bit?
cu
-- modified at 6:28 Friday 12th May, 2006
|
|
|
|
|
So I forgot that pre eats up the < and >. Can't you guess that it's supposed to be static_cast<RGBQUAD*>(Img1)?
You can choose to use 8-bit but I didn't see you set your palette.
|
|
|
|
|
<br />
error C2440: 'static_cast' : cannot convert from 'unsigned char *' to 'RGBQUAD *'<br />
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast<br />
<br />
<br />
RGB2Gray(ActImage, GrayMap, FireCapture->grabBufferSize);<br />
<br />
how can i set a palette in my case and display the grayscale image?<br />
cu
-- modified at 11:29 Friday 12th May, 2006
|
|
|
|
|
Hi
I have i combobox with dropdownlist style ( and ownerdrawfixed | havestrings)
am filling it using addstring method
how can i get the text of an item in the drawitem method?
thanks alot
|
|
|
|
|
if you use WM_DRAWITEM
maybe it is some helpful to you
CString str;
GetLBText(lpDrawItem->itemID, str);
|
|
|
|
|
thanks alot it worked fine in drawitem method after testing that the itemid is in the valid range of indices.
but the items seems so close to each other, how can this be solved?
and how can i remove the border from the edit area of the combo?
again thanks alot for your help
|
|
|
|
|
|
like this only enter numbers in combobox
<br />
COMBOBOXINFO m_info;<br />
ZeroMemory(&m_info, sizeof(COMBOBOXINFO));<br />
m_info.cbSize = sizeof(COMBOBOXINFO);<br />
m_Combo.GetComboBoxInfo(&m_info);<br />
<br />
ModifyStyle(m_info.hwndItem,0,ES_NUMBER,0);<br />
|
|
|
|
|
Hi there,
I have a program that uses couple of sockets to communicate with two different devices. I have a socket class that supports both UDP and TCP (and Srever and client). I use INI file to specify what socket to use for every application. For the incomming messages in my code's enterance where I need to receive data from different clients, works for UDP socket but does not work for TCP.
Can any one tell me what could be the problem?
The following shows a part of my INI file for UDP socket. what changes should I make for the TCP one?
[DataLink Socket]
CfgTCP=TCP
CfgServer=TRUE
CfgLocalPort=1250
CfgRemotePort=1250
CfgRemoteAddr=127.0.0.1
CfgLocalAddr=127.0.0.1
CfgSrvMaxConnLimit=10
CfgCommType=BOTH
CfgKeepSockOpen=TRUE
Appreciate your help,
|
|
|
|
|
Hi
Please search on code project for examples
KK
|
|
|
|
|
hello all
I need to find a red " + " in a image and i want a good algorithm .
thank you
-- modified at 9:48 Thursday 11th May, 2006
|
|
|
|
|