bitmapinfo and bitmapfileheader structures

cpp Romania
  • 10 years ago
     
    Hi

    i run into this code.. :

    void CVidTestDlg::OnCapture()
    {
    CString Filter;
    CString Filename;
    CRect Rect;

    Filter = "Bitmap Files (*.bmp)|*.bmp|AVI Files (*.avi)|*.avi||";

    CFileDialog FileDlg(FALSE, "BMP", NULL,
    OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
    Filter,
    this);

    if (FileDlg.DoModal() == IDOK)
    {
    RedrawWindow();

    Filename = FileDlg.GetPathName();

    Capture(m_VFWImageProc, Filename);

    m_VideoDisplay.GetWindowRect(Rect);
    ScreenToClient(Rect);

    m_VFWImageProc.EnablePreviewVideo(*this, Rect.TopLeft().x,Rect.TopLeft().y);
    }
    }



    BOOL Capture(CVFWImageProcessor &ImageProc, LPCTSTR Filename)

    {
    ULONG Length = 0;
    CFile File;
    BOOL Ret = FALSE;
    CHAR Ext[_MAX_EXT];

    _splitpath(Filename,NULL,NULL,NULL,Ext);

    if (stricmp(Ext,".avi") == 0)
    {
    Ret = ImageProc.CaptureAVI(Filename,4.0,10,10);
    }
    else if (stricmp(Ext,".bmp") == 0)
    {
    BITMAPINFO *Bitmap = NULL;
    BITMAPFILEHEADER bfh;

    ImageProc.CaptureDIB(&Bitmap,0,&Length);

    if (Bitmap)
    {
    File.Open(Filename,CFile::modeCreate |
    CFile::modeWrite |
    CFile::shareDenyNone |
    CFile::typeBinary);

    bfh.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
    bfh.bfSize = (DWORD) Length + sizeof(BITMAPFILEHEADER);
    bfh.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
    sizeof(BITMAPINFOHEADER) +
    Bitmap->bmiHeader.biClrUsed * sizeof (RGBQUAD);
    bfh.bfReserved1 = 0;
    bfh.bfReserved2 = 0;



    File.Write(&bfh,sizeof(bfh));
    File.Write(Bitmap,Length);

    File.Close();

    Ret = TRUE;

    delete Bitmap;
    }

    this is the code that is resposible for capturing a image from usb webcam and saving to hard driver

    Function : CaptureDIB
    Arguments : Bitmap (output) - Pointer to bitmap to receive image.
    If *Bitmap = NULL, then allocation will
    be performed automatically.
    BitmapLength (input) - Size of Bitmap if *Bitmap is not NULL.
    RetBitmapLength (output) - Actual size of image.
    Return : TRUE Success, FALSE Failed.
    Description: Captures a DIB image from video capture device.

    As you see he uses some structs BITMAPINFO BITMAPFILEHEADER wihich togheter is the bitmap file. and writes it down to file.

    now my problem...

    i must make a dll wich exports symbols and a function within it , lets call it Capture that will return a bitmap (whole bitmap including header)

    but i dont know how to copy the both struct within a buffer or something and return it.

    can someone help. does someone get me..

    sorry for bad explanation . i`m not champion at c++







































































































  • 10 years ago

    Creating a new struct (BITMAPFILEHEADER_BITMAPINFO), that contains all the members of BITMAPINFO & BITMAPFILEHEADER ?

     

    struct BITMAPFILEHEADER_BITMAPINFO
    {
        WORD    bfType;
        DWORD   bfSize;
        WORD    bfReserved1;
        WORD    bfReserved2;
        DWORD   bfOffBits;





        BITMAPINFOHEADER    bmiHeader;
        RGBQUAD             bmiColors[1];

    };

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The trouble with programmers is that you can never tell what a programmer is doing until it's too late.” - Seymour Cray