Click here to Skip to main content
15,886,518 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with my c++ project :'( Pin
CPallini23-Mar-09 1:49
mveCPallini23-Mar-09 1:49 
GeneralRe: Problem with my c++ project :'( Pin
TinyDevices23-Mar-09 2:05
professionalTinyDevices23-Mar-09 2:05 
QuestionRe: Problem with my c++ project :'( Pin
David Crow23-Mar-09 3:23
David Crow23-Mar-09 3:23 
QuestionGet String size Height and Width Pin
~Khatri Mitesh~23-Mar-09 1:04
~Khatri Mitesh~23-Mar-09 1:04 
AnswerRe: Get String size Height and Width Pin
Cedric Moonen23-Mar-09 1:06
Cedric Moonen23-Mar-09 1:06 
AnswerRe: Get String size Height and Width Pin
led mike23-Mar-09 4:41
led mike23-Mar-09 4:41 
AnswerRe: Get String size Height and Width Pin
Joe Woodbury23-Mar-09 12:24
professionalJoe Woodbury23-Mar-09 12:24 
QuestionVIDEO FOR WINDOWS - drawing TEXTOUT Pin
pabloesso23-Mar-09 0:24
pabloesso23-Mar-09 0:24 
Hi everyone Smile | :)


I'm stuck with the code which renders a preview of a Camera using VFW.

The thing is that i want to do TextOut on this image within FrameCallback,
but the textout comes some kind of a bottom-up ?

The idea is to store avi sequence with a text drawn inside (generally a date).

Here is the code:

I enumerate available devices, and connect to the one i choose.
Then i do


BOOL SetVideoFormatRGB()<br />
{<br />
    DWORD size = capGetVideoFormatSize(ghWndCap);<br />
<br />
    if ( size <= 0 )<br />
    {<br />
     <br />
        return FALSE;<br />
    }<br />
<br />
    void* pBuffer = new BYTE[size];<br />
    BITMAPINFO* pBitmapInfo = (BITMAPINFO*) pBuffer;<br />
<br />
    if ( capGetVideoFormat(ghWndCap, pBuffer, size) <= 0 )<br />
    {<br />
      <br />
        return FALSE;<br />
    }<br />
<br />
    pBitmapInfo->bmiHeader.biBitCount = 24;<br />
    pBitmapInfo->bmiHeader.biCompression = 0;<br />
    pBitmapInfo->bmiHeader.biSizeImage = pBitmapInfo->bmiHeader.biWidth * pBitmapInfo->bmiHeader.biHeight * 3;<br />
 <br />
<br />
    if ( ! capSetVideoFormat(ghWndCap, pBitmapInfo, size) )<br />
    {<br />
      <br />
        return FALSE;<br />
    }<br />
<br />
    <br />
    g_nBitCount = pBitmapInfo->bmiHeader.biBitCount;<br />
    g_nBitsPerPixel = pBitmapInfo->bmiHeader.biBitCount;<br />
<br />
    <br />
    return TRUE;<br />
}



Next thing - i create a Callback for VFW:

capSetCallbackOnFrame(ghWndCap, (FARPROC)FrameCallbackProc);


And process each frame :

<br />
 LRESULT PASCAL FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)<br />
{	<br />
  <br />
    if ( g_nBitCount != 24 )   // only RGB format !<br />
        return 0;<br />
<br />
     <br />
    if ( ! g_hFrameBitmap )   // failed<br />
        return 0;<br />
 <br />
	BeginPaint(hWnd,&ps);<br />
 <br />
    <br />
	<br />
SetBitmapBits(g_hFrameBitmap, g_nImageWidth*g_nImageHeight*3, lpVHdr->lpData);<br />
 <br />
<br />
<br />
<br />
 <br />
 <br />
	<br />
SetBkMode(g_hFrameDC,TRANSPARENT);<br />
SelectObject(g_hFrameDC, FONTmain);<br />
SetTextColor(g_hFrameDC,RGB(0,0,0));<br />
hPen = CreatePen(0, 1, RGB(210,210,210));<br />
SelectObject(g_hFrameDC, hPen);<br />
Rectangle(g_hFrameDC,  0,0,  320,100);<br />
TextOut(g_hFrameDC,2,2,"AAAAAAAAAAA",10);<br />
 <br />
 GetBitmapBits(g_hFrameBitmap, g_nImageWidth*g_nImageHeight*3, lpVHdr->lpData);<br />
 <br />
<br />
<br />
		EndPaint(hWnd,&ps); <br />
return (LRESULT)true;<br />
 }



This code does the trick but all i draw on g_hFrameBitmap is bottom-up, so point:

0,0 is on the bottom left side of whole image. The string "AAAAA..." also comes
bottom up.

g_hFrameBitmap is created as:

<br />
void CreateGraphicObjects(HWND hWnd)<br />
{<br />
  <br />
    g_hFrameDC = CreateCompatibleDC(GetDC(hWnd));<br />
     <br />
 <br />
	 <br />
    <br />
    memset(&lpbi, 0, sizeof(lpbi));<br />
    lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))];<br />
    lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
    lpbi->bmiHeader.biWidth = g_nImageWidth;<br />
    lpbi->bmiHeader.biHeight = -240;<br />
    lpbi->bmiHeader.biPlanes = 1;<br />
    lpbi->bmiHeader.biBitCount = 24;<br />
    lpbi->bmiHeader.biCompression = BI_RGB;<br />
    lpbi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)g_nImageWidth * 8) * g_nImageHeight;<br />
    lpbi->bmiHeader.biXPelsPerMeter = 0;<br />
    lpbi->bmiHeader.biYPelsPerMeter = 0;<br />
    lpbi->bmiHeader.biClrUsed = 0;<br />
    lpbi->bmiHeader.biClrImportant = 0;<br />
    <br />
 <br />
<br />
    g_hFrameBitmap=  CreateDIBSection( <br />
        NULL,                       // DC - we don't need it here <br />
        lpbi,                       // BITMAPINFOHEADER pointer<br />
        DIB_RGB_COLORS,             // palette is in BITMAPINFO, contains RGBQUAD entries (doesn't matter for RGB)<br />
        (void **)&pBits,             // output pointer to bitmap bits<br />
        NULL, <br />
        0 ); <br />
 <br />
	<br />
    delete[] lpbi;<br />
    SelectObject(g_hFrameDC, (HBITMAP)g_hFrameBitmap);<br />
<br />
	<br />
}<br />



Any chance to get this resolved? I've tried to pass negative values to bitmap header - no luck.


Best reagards!
AnswerRe: VIDEO FOR WINDOWS - drawing TEXTOUT Pin
Jonathan Davies23-Mar-09 2:52
Jonathan Davies23-Mar-09 2:52 
AnswerRe: VIDEO FOR WINDOWS - drawing TEXTOUT Pin
Jonathan Davies23-Mar-09 3:32
Jonathan Davies23-Mar-09 3:32 
GeneralRe: VIDEO FOR WINDOWS - drawing TEXTOUT Pin
pabloesso23-Mar-09 3:40
pabloesso23-Mar-09 3:40 
GeneralRe: VIDEO FOR WINDOWS - drawing TEXTOUT Pin
pabloesso24-Mar-09 1:23
pabloesso24-Mar-09 1:23 
GeneralRe: VIDEO FOR WINDOWS - drawing TEXTOUT Pin
pabloesso29-Mar-09 7:02
pabloesso29-Mar-09 7:02 
AnswerRe: VIDEO FOR WINDOWS - drawing TEXTOUT Pin
pabloesso29-Mar-09 7:16
pabloesso29-Mar-09 7:16 
QuestionDoubt in Run time polymerphisim Pin
Cool_Phillip23-Mar-09 0:04
Cool_Phillip23-Mar-09 0:04 
AnswerRe: Doubt in Run time polymerphisim Pin
«_Superman_»23-Mar-09 0:06
professional«_Superman_»23-Mar-09 0:06 
AnswerRe: Doubt in Run time polymerphisim Pin
CPallini23-Mar-09 0:11
mveCPallini23-Mar-09 0:11 
GeneralRe: Doubt in Run time polymerphisim Pin
Cool_Phillip23-Mar-09 1:08
Cool_Phillip23-Mar-09 1:08 
GeneralRe: Doubt in Run time polymerphisim Pin
CPallini23-Mar-09 1:17
mveCPallini23-Mar-09 1:17 
QuestionHyperlink for send mail with use of static control? Pin
Le@rner22-Mar-09 23:51
Le@rner22-Mar-09 23:51 
AnswerRe: Hyperlink for send mail with use of static control? Pin
«_Superman_»23-Mar-09 0:04
professional«_Superman_»23-Mar-09 0:04 
GeneralRe: Hyperlink for send mail with use of static control? [modified] Pin
Le@rner23-Mar-09 0:54
Le@rner23-Mar-09 0:54 
GeneralRe: Hyperlink for send mail with use of static control? Pin
«_Superman_»23-Mar-09 1:36
professional«_Superman_»23-Mar-09 1:36 
GeneralRe: Hyperlink for send mail with use of static control? Pin
Le@rner23-Mar-09 1:48
Le@rner23-Mar-09 1:48 
QuestionHow to clean contents of a file Pin
PankajB22-Mar-09 23:33
PankajB22-Mar-09 23:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.