Click here to Skip to main content
15,868,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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.

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
 
Share this answer
 
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.
C++
HDC hdc = ::GetDC(NULL);
    CDC MemDc;
    MemDc.CreateCompatibleDC( GetDC() );


2) Prepare a Bitmap with the captured image.
C++
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.DeleteObject();
        m_BitmapObject.Attach( hbmDest );
    }
}


3) Attach the Bitmap with the memory DC.
C++
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.
C++
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.
C++
// Get Contents from DC.
GetDIBits( MemDc.m_hDC, (HBITMAP)m_BitmapObject.m_hObject, 0, m_nImageHeight, pbyData, &stBitmapInfo, DIB_RGB_COLORS );
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900