Thread: displaying bitmap

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    4

    Unhappy displaying bitmap

    I have a program which acquires images using a camera .Every thing is fine as long as it is not displaying images.
    But i need to display images.I m using DIBs in this case.
    I hav narrowed the bug to the DIBINFO header.

    im fillig out the DIBINFO header like this

    BITMAPINFO buf;

    buf.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    buf.bmiHeader.biWidth = width;
    buf.bmiHeader.biHeight = height;
    buf.bmiHeader.biPlanes = 1;
    buf.bmiHeader.biBitCount = 8;
    buf.bmiHeader.biCompression = BI_RGB;
    buf.bmiHeader.biSizeImage = width*height;
    buf.bmiHeader.biXPelsPerMeter = 0;
    buf.bmiHeader.biYPelsPerMeter = 0;
    buf.bmiHeader.biClrUsed = 256;
    buf.bmiHeader.biClrImportant = 0;
    buf.bmiColors[0].rgbBlue = buf.bmiColors[0].rgbGreen = buf.bmiColors[0].rgbRed = 0;
    buf.bmiColors[0].rgbReserved = 0;



    I hope everthing is self explenatory.
    Is there anything wrong in the I way fill it out.
    OR is there any other way i can display images got from a camera ?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I realy don't know much about the bitmap format but it seams you have set the header to an 8 bit bitmap with 256 colors but set the compresion too BI_RGB which I think requires at least 24 bits sine (R)ed (G)reen and (B)lue would each use 8 bits. For a 256 bit image I think you need a pallate of colors. I'm sorry if I'm not correct this is just a though.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    4

    Unhappy

    thanx any way
    but i need more than tat
    can anyone tell me how to display images got from a camera real time

    any method will do ,not just DIBs

    no text book provides tat help

    Heeeelp

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    39
    Quote Originally Posted by sohnythomas
    can anyone tell me how to display images got from a camera real time
    Hi shony,

    One way of capturing images from a camera would be to develop a compatible video capturing driver for the camera. You will need to go through the Windows DDK documentation to be able to build one.
    Where do u plan to display these images? on some application that u build?

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>can anyone tell me how to display images got from a camera real time

    what format do you get the images in?



    Search here for 'buffering' or 'double buffering'.

    This uses CreateCompatibleDC() and CreateCompatibleBitmap() in which you store the image.
    When the image changes you draw the new image to the buffer DC.

    Then call for the apps screen to be painted (WM_PAINT msg)

    In the WM_PAINT handler you draw the buffer DC to the screen DC (got from the paint msg function BeginPaint() )
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    4

    Unhappy

    i already know how to get an image from camera
    but the problem is displaying it
    the image is stored in array of datatype BYTE or DWORD

    but im not able to display it on the screen

    i will check in to u r suggestion anyway, thanx

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Have you tried......
    CreateCompatibleDC()
    CreateCompatibleBitmap() // the same size as your image

    then SetDIBits() to copy your image to the BMP

    In the paint handler BitBlt() your image to the HDC returned by BeginPaint()

    I don't think it will work (at differing screen colour depths).



    these pieces are cut from a screen capture function of mine (where I have the image as a bmp and I am copying it)

    You would need to SetDIBits() to copy your array to the bmp (ie transfer image to new blank bmp)

    In your case cClrBits = 8
    Code:
        PBITMAPINFO pbmi; 
        
    
        pbmi = (PBITMAPINFO) GlobalAlloc(LPTR, sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*(1<< cClrBits)); 
    
    //error check removed
    
        pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
        pbmi->bmiHeader.biWidth = bmp.bmWidth; 
        pbmi->bmiHeader.biHeight = bmp.bmHeight; 
        pbmi->bmiHeader.biPlanes = bmp.bmPlanes; 
        pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel; 
        if (cClrBits < 24) 
            pbmi->bmiHeader.biClrUsed = (1<<cClrBits); 
    
        // If the bitmap is not compressed, set the BI_RGB flag. 
        pbmi->bmiHeader.biCompression = BI_RGB; 
    
    
        // For Windows NT, the width must be DWORD aligned unless 
        // the bitmap is RLE compressed. 
        // For Windows 95/98/Me, the width must be WORD aligned unless the 
        // bitmap is RLE compressed.
        pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
                                      * pbmi->bmiHeader.biHeight; 
        // Set biClrImportant to 0, indicating that all of the 
        // device colors are important. 
         pbmi->bmiHeader.biClrImportant = 0; 
    
    //next function 
    //set header
        BITMAPFILEHEADER hdr;       // bitmap file-header 
    
        hdr.bfType = 0x4d42;        // 0x42 = "B" 0x4d = "M" 
        // Compute the size of the entire file. 
        hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage); 
        hdr.bfReserved1 = 0; 
        hdr.bfReserved2 = 0;
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    May 2005
    Posts
    4

    Smile

    it worked beutifully thanx

  9. #9
    Registered User
    Join Date
    May 2005
    Posts
    19
    how to display jpeg image by using borland C++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmap Displaying Problem
    By MadCow257 in forum Game Programming
    Replies: 0
    Last Post: 01-25-2005, 05:21 PM
  2. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  3. Displaying a Bitmap
    By Speedy5 in forum Windows Programming
    Replies: 2
    Last Post: 01-18-2004, 05:04 PM
  4. Displaying a seperate bitmap for each menu button
    By Magriep in forum Windows Programming
    Replies: 1
    Last Post: 03-26-2002, 11:40 PM
  5. Displaying bitmap on db
    By JrKoas38 in forum C++ Programming
    Replies: 1
    Last Post: 09-19-2001, 06:55 PM