Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:46:33+00:00 2026-05-26T02:46:33+00:00

How can I draw directly on video frame (webcam)? I need to place a

  • 0

How can I draw directly on video frame (webcam)? I need to place a watermark in the corner, so when I capture the video to the file, this watermark should be on each frame?

My setup is as follows:

struct Sampler : public CBaseVideoRenderer 
{
    Sampler( IUnknown* unk, HRESULT *hr ) : CBaseVideoRenderer(__uuidof(CLSID_Sampler), NAME("Frame Sampler"), unk, hr) {};

    HRESULT CheckMediaType(const CMediaType *media ) 
    {    
        VIDEOINFO* vi; 
        if(!IsEqualGUID( *media->Subtype(), MEDIASUBTYPE_RGB24) || !(vi=(VIDEOINFO *)media->Format()) ) return E_FAIL;
        bmih=vi->bmiHeader; 
        return  S_OK;
    }
    HRESULT DoRenderSample(IMediaSample *sample)
    {
            int w=bmih.biWidth;
            int h=bmih.biHeight;
            BYTE* data; sample->GetPointer( &data ); 
            HDC dc=GetDC(hCameraWindow);
            BITMAPINFO bmi={0}; bmi.bmiHeader=bmih; RECT r; GetClientRect( hCameraWindow, &r ); 
            StretchDIBits(dc,0,0,r.right,r.bottom,0,0,bmih.biWidth,bmih.biHeight,data,&bmi,DIB_RGB_COLORS,SRCCOPY);
            ReleaseDC(hCameraWindow,dc);
            return  S_OK;
    }
    HRESULT ShouldDrawSampleNow(IMediaSample *sample, REFERENCE_TIME *start, REFERENCE_TIME *stop) 
    {
        return S_OK; // disable droping of frames
    }
};

And the initialization :

hCameraWindow= CreateWindowEx(WS_EX_CLIENTEDGE, "Static", NULL, WS_CHILD | WS_VISIBLE , 20, 5, 640, 480, okno, NULL, GetModuleHandle(NULL), NULL);
ShowWindow(hCameraWindow,SW_SHOW);
if(!hCameraWindow)exit(0);


IGraphBuilder*  graph= 0;       hr = CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,IID_IGraphBuilder, (void **)&graph );
IMediaControl*  ctrl = 0;       hr = graph->QueryInterface( IID_IMediaControl, (void **)&ctrl );
    IMediaEventEx*  mediaEvent=0;   hr = graph->QueryInterface(IID_IMediaEvent, (LPVOID *) &mediaEvent);
    IVideoWindow*   m_pVWMoniker=0; hr = graph->QueryInterface(IID_IVideoWindow, (LPVOID *) &m_pVWMoniker);

 m_pVWMoniker->put_Owner((OAHWND)hCameraWindow);
 m_pVWMoniker->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
 m_pVWMoniker->put_Visible(OATRUE);
 m_pVWMoniker->put_MessageDrain((OAHWND)hCameraWindow);

 Sampler*        sampler      = new Sampler(0,&hr); 


IPin*           rnd  = 0; hr = sampler->FindPin(L"In", &rnd);
                          hr = graph->AddFilter((IBaseFilter*)sampler, L"Sampler");

ICreateDevEnum* devs = 0; hr = CoCreateInstance (CLSID_SystemDeviceEnum, 0, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &devs);
IEnumMoniker*   cams = 0; hr = devs?devs->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &cams, 0):0;  
IMoniker*       mon  = 0; hr = cams?cams->Next (1, &mon, 0):0;
IBaseFilter*    cam  = 0; hr = mon?mon->BindToObject(0,0,IID_IBaseFilter, (void**)&cam):0;
IEnumPins*      pins = 0; hr = cam?cam->EnumPins(&pins):0; 
IPin*           cap  = 0; hr = pins?pins->Next(1,&cap, 0):0;
                          hr = graph->AddFilter(cam, L"Capture Source"); 
    // Change resolution
    IAMStreamConfig *pConfig=0;
    if(cap->QueryInterface( IID_IAMStreamConfig, (void **)&pConfig) == S_OK )
    {
        int iCount = 0;
        int iSize = 0;      
        hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
        VIDEO_STREAM_CONFIG_CAPS caps;
        AM_MEDIA_TYPE *pmtConfig;
        for(int i=0;i<iSize;i++)
        {           
            pConfig->GetStreamCaps(i, &pmtConfig, (BYTE*)&caps);
            // if a resoltion has been found, set format to it
            if( caps.MaxOutputSize.cx == 640  && caps.MinOutputSize.cy == 480 )
            {
                pConfig->SetFormat(pmtConfig);
            }

        }
        DeleteMediaType(pmtConfig);
    } 

hr = graph->Connect(cap,rnd);
hr = graph->Render( cap);
hr = ctrl->Run();

I can access the frame with “DoRenderSample”. DShow really is quite non users friendly for DShow beginners.

I switched from VFW and I need to draw with GDI+ on the frame, is it possible with SetBitmapBits / GetBitmapBits?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:46:34+00:00Added an answer on May 26, 2026 at 2:46 am

    Resolved
    Ok I’ve got it working, if anyone is interested – look below into the code, it will draw a text with GDIplus – no error handling, i leave it for yourself.

    int m_stride;
    VIDEOINFOHEADER m_videoInfo;
    
    
        HRESULT CheckMediaType(const CMediaType *media ) 
        {    
            VIDEOINFO* vi; 
            if(!IsEqualGUID( *media->Subtype(), MEDIASUBTYPE_RGB24) || !(vi=(VIDEOINFO *)media->Format()) ) return E_FAIL;
            bmih=vi->bmiHeader; 
            m_stride = bmih.biBitCount / 8 * bmih.biWidth;       
            return  S_OK;
        }
    
     HRESULT DoRenderSample(IMediaSample *sample)
        {       BYTE* data; 
                int w=bmih.biWidth;
                int h=bmih.biHeight;
                int len = sample->GetActualDataLength();
                sample->GetPointer( &data ); 
    
    
                BITMAPINFOHEADER bih = bmih;
                Bitmap bmp(bih.biWidth, bih.biHeight, (bmih.biBitCount/8*bmih.biWidth), PixelFormat24bppRGB, data);
                Graphics graphics(&bmp);
                WCHAR wavists[1024];    
                char txt[1024];
                sprintf(txt,"THIS TEXT IS DISPLAYED ON EACH FRAME");MultiByteToWideChar( GetACP(), 0, txt, -1, wavists, strlen(txt));       
                graphics.DrawString(wavists,strlen(txt),&Font(&FontFamily(L"Tahoma"), 16, FontStyleBold, UnitPixel),PointF(0,0),&SolidBrush(Color(200,0,255,0)));
    
    
    
    
    
                HDC dc=GetDC(hCameraWindow);
                BITMAPINFO bmi={0}; bmi.bmiHeader=bmih; RECT r; GetClientRect( hCameraWindow, &r ); 
                StretchDIBits(dc,0,0,r.right,r.bottom,0,0,bmih.biWidth,bmih.biHeight,data,&bmi,DIB_RGB_COLORS,SRCCOPY);
                ReleaseDC(hCameraWindow,dc);
    
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can draw many things using this : NSString *imagePath = [[NSBundle mainBundle] pathForResource:@dummy2.png
How I can draw picture from drawable resources in place where I click? I
I have an area where the user can draw using a finger. This area
I want Flash to communicate directly with dll files. How can I do this?
Possible Duplicate: Drawing on desktop in Mac OS X How can I draw directly
I can draw a circle around a given point (x,y) with a command like
i can draw a string/image... with drawInRect/drawAtPoint. but how about if i want to
How i can draw hand free graphic objects in windows 8, like paint can.
In Visual studio I can draw 13 different application-icons in different resolutions and color
Any idea how I can draw Bullet Points using Flex? instead of using image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.