Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. How can I create a colour btimap ?

How can I create a colour btimap ?

Scheduled Pinned Locked Moved ATL / WTL / STL
questionc++graphicsdata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darked developer
    wrote on last edited by
    #1

    Hi everyone. Recently I've began to study WTL programming and I 've got a question. Please explain me how can I create a colour bitmap from array of bits? Not colour bitmap I create like this: HBITMAP btmp; LPBITMAPINFO pbi; LPBITMAPINFOHEADER pbmph; bool CDisplay::initBmp(byte* Img) { if(pbi != NULL) delete [] pbi; if(btmp != NULL) DeleteObject(btmp); int headerSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256; try { pbi = (LPBITMAPINFO)new char [headerSize]; pbmph = &(pbi->bmiHeader); memset(pbmph, 0, headerSize); pbmph->biSize = sizeof(BITMAPINFOHEADER); pbmph->biPlanes = 1; pbmph->biCompression = BI_RGB; pbmph->biClrUsed = 256; pbmph->biClrImportant = 256; pbmph->biBitCount = 8; // fill RGBQUAD LPRGBQUAD pRGBQ = (LPRGBQUAD)((LPSTR)pbmph + pbmph->biSize); for( int i = 0; i < 256; i++ ) { pRGBQ[i].rgbBlue = pRGBQ[i].rgbGreen = pRGBQ[i].rgbRed = i; } } catch(...) { return false; } pbmph->biWidth = MaxX[0]; pbmph->biHeight = MaxY[0]; pbmph->biSizeImage = MaxX[0]*MaxY[0]; btmp = CreateDIBitmap(GetDC(), pbmph, CBM_INIT, Img, pbi, DIB_RGB_COLORS); return true; } How create colour bitmap? P.S.: Sorry for my english if I wrote with errors. Nulla dies sine linea !!!

    R 1 Reply Last reply
    0
    • D Darked developer

      Hi everyone. Recently I've began to study WTL programming and I 've got a question. Please explain me how can I create a colour bitmap from array of bits? Not colour bitmap I create like this: HBITMAP btmp; LPBITMAPINFO pbi; LPBITMAPINFOHEADER pbmph; bool CDisplay::initBmp(byte* Img) { if(pbi != NULL) delete [] pbi; if(btmp != NULL) DeleteObject(btmp); int headerSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256; try { pbi = (LPBITMAPINFO)new char [headerSize]; pbmph = &(pbi->bmiHeader); memset(pbmph, 0, headerSize); pbmph->biSize = sizeof(BITMAPINFOHEADER); pbmph->biPlanes = 1; pbmph->biCompression = BI_RGB; pbmph->biClrUsed = 256; pbmph->biClrImportant = 256; pbmph->biBitCount = 8; // fill RGBQUAD LPRGBQUAD pRGBQ = (LPRGBQUAD)((LPSTR)pbmph + pbmph->biSize); for( int i = 0; i < 256; i++ ) { pRGBQ[i].rgbBlue = pRGBQ[i].rgbGreen = pRGBQ[i].rgbRed = i; } } catch(...) { return false; } pbmph->biWidth = MaxX[0]; pbmph->biHeight = MaxY[0]; pbmph->biSizeImage = MaxX[0]*MaxY[0]; btmp = CreateDIBitmap(GetDC(), pbmph, CBM_INIT, Img, pbi, DIB_RGB_COLORS); return true; } How create colour bitmap? P.S.: Sorry for my english if I wrote with errors. Nulla dies sine linea !!!

      R Offline
      R Offline
      Rory Solley
      wrote on last edited by
      #2

      You might want to look at CreateDIBSection. This is similar to what you already have (it will return a HBITMAP handle and a pointer to the bits). You can directly modify the bits via that pointer and use the handle for selecting the object into DCs. If you simply want to create a 24-bit colour image, you don't need to create palette information in the BITMAPINFOHEADER (set those values to 0). Then simply write an RGB TRIPLE (Blue, Green, Red) for each pixel using the pointer. Remember you will need to pad each scanline to the DWORD boundary. If you want to write a 256-colour (paletted) image, you will need to provide a colour table. Check out MSDN documentation for that information. Another gotcha is that if you want the bitmap to be "top-down" i.e. pixel (0,0) is in the top-left corner, you must specify a NEGATIVE height value in the BITMAPINFOHEADER structure. Hope that helps

      D 1 Reply Last reply
      0
      • R Rory Solley

        You might want to look at CreateDIBSection. This is similar to what you already have (it will return a HBITMAP handle and a pointer to the bits). You can directly modify the bits via that pointer and use the handle for selecting the object into DCs. If you simply want to create a 24-bit colour image, you don't need to create palette information in the BITMAPINFOHEADER (set those values to 0). Then simply write an RGB TRIPLE (Blue, Green, Red) for each pixel using the pointer. Remember you will need to pad each scanline to the DWORD boundary. If you want to write a 256-colour (paletted) image, you will need to provide a colour table. Check out MSDN documentation for that information. Another gotcha is that if you want the bitmap to be "top-down" i.e. pixel (0,0) is in the top-left corner, you must specify a NEGATIVE height value in the BITMAPINFOHEADER structure. Hope that helps

        D Offline
        D Offline
        Darked developer
        wrote on last edited by
        #3

        TNX, That helped me. I did it. Nulla dies sine linea !!!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups