Click here to Skip to main content
13,559,184 members
Rate this:
Please Sign up or sign in to vote.
Hi everyone, I am capturing images from webcam using C (capCreateCaptureWindow, capDriverConnect etc). Now I wanna put a date stamp somewhere on the image that was captured. I know that we can put a pixel through PutPixel but I don't have any idea how to put a date stamp. Please help me. Thank in Advance. God Bless you all.
Posted 1-Nov-12 18:01pm
nv3 2-Nov-12 4:53am
Note that there are two methods to attach a date stamp:

(1) You modify the image contents to show a human readable date/time stamp in a corner of the image.

(2) You attach a machine readable date/time stamp to the image by attaching some extra data such as EXIF data. That will only work for certain image format though, like JPEG or TIFF. EXIF data are for example attached automatically by most digital consumer cameras. If you want to go this way, search for EXIF in Wikipedia and find a library package that allows you to add an EXIF data package to your images.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use this great article[^] for reference on how to work with the capture callbacks, and how to convert lpData to BITMAP. Once you have the BITMAP, you can very easily attach it to a MemDC, DrawText and save the bitmap
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If GDI functions can be used, you can prepare a memory Dc and attach the captured image to the memory DC. Then Draw the timestamp text to the memory DC, using TextOut or DrawText. After Textout to the memory DC, Read bitmap and it will provide the captured image with the text.

1) Prepare a memory DC.
HDC hdc = ::GetDC(NULL);
    CDC MemDc;
    MemDc.CreateCompatibleDC( GetDC() );

2) Prepare a Bitmap with the captured image.
CBitmap m_BitmapObject;
HBITMAP hbmDest = ::CreateCompatibleBitmap(hdc, m_nImageWidth, m_nImageHeight);
BITMAPINFO stBitmapInfo;
stBitmapInfo.bmiHeader.biClrImportant = 0;
stBitmapInfo.bmiHeader.biClrUsed = 0;
stBitmapInfo.bmiHeader.biCompression = 0;
stBitmapInfo.bmiHeader.biPlanes = 1;
stBitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
stBitmapInfo.bmiHeader.biXPelsPerMeter = 0;
stBitmapInfo.bmiHeader.biYPelsPerMeter = 0;
stBitmapInfo.bmiHeader.biBitCount = 3 * 8;
stBitmapInfo.bmiHeader.biSizeImage = m_nImageWidth * m_nImageHeight;
stBitmapInfo.bmiHeader.biHeight = m_nImageHeight;
stBitmapInfo.bmiHeader.biWidth = m_nImageWidth;
stBitmapInfo.bmiColors[0].rgbBlue = 0x0;
stBitmapInfo.bmiColors[0].rgbGreen = 0x0;
stBitmapInfo.bmiColors[0].rgbRed = 0x0;
stBitmapInfo.bmiColors[0].rgbReserved = 0x0;

if (hbmDest)
    if (SetDIBits(hdc, hbmDest, 0, m_nImageHeight, m_pbyImageData, &stBitmapInfo, DIB_RGB_COLORS))
        m_BitmapObject.Attach( hbmDest );

3) Attach the Bitmap with the memory DC.
MemDc.SelectObject( m_BitmapObject );

4) Prepare time stamp text by calling gettime() and other string formatting functions.
5) Call TextOut() with the time stamp text to the DC.
BOOL b = MemDc.TextOut( 0,0, szTimestampText ); // Time stamp text.

6) Read contents of the bitmap.// This bitmap will have the captured image and the timestamp text.
// Get Contents from DC.
GetDIBits( MemDc.m_hDC, (HBITMAP)m_BitmapObject.m_hObject, 0, m_nImageHeight, pbyData, &stBitmapInfo, DIB_RGB_COLORS );

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03-2016 | 2.8.180515.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100