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. C / C++ / MFC
  4. How to get pixel value in BITMAP?

How to get pixel value in BITMAP?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
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.
  • C Offline
    C Offline
    charmingzuo
    wrote on last edited by
    #1

    I want to use following method, but it doesn't work. HBITMAP hBitmap; // Here hBitmap is already available; CBitmap *pBitmap; pBitmap->Attach(hBitmap); BITMAP bm; GetObject(hBitmap, sizeof(BITMAP), &bm); I don't know the function of "LVOID bmBits" in BITMAP structure. According to MSDN, "LVOID bmBits" is the pointer to the pixel value area, so I think I can get pixel value (R,G,B) using loop (bm.bmBits)+ +, unfortunately it cann't work. Maybe it is a pointer to the whole structure, including BITMAPFILEHEADER, BITMAPINFO ?? Thanks in advance.:confused: Nianming

    T 1 Reply Last reply
    0
    • C charmingzuo

      I want to use following method, but it doesn't work. HBITMAP hBitmap; // Here hBitmap is already available; CBitmap *pBitmap; pBitmap->Attach(hBitmap); BITMAP bm; GetObject(hBitmap, sizeof(BITMAP), &bm); I don't know the function of "LVOID bmBits" in BITMAP structure. According to MSDN, "LVOID bmBits" is the pointer to the pixel value area, so I think I can get pixel value (R,G,B) using loop (bm.bmBits)+ +, unfortunately it cann't work. Maybe it is a pointer to the whole structure, including BITMAPFILEHEADER, BITMAPINFO ?? Thanks in advance.:confused: Nianming

      T Offline
      T Offline
      twing
      wrote on last edited by
      #2

      maybe u can try this: unsigned char *px = new unsigned char[bm.bmHeight*bm.bmWidthBytes]; bitmap->GetBitmapBits(bm.bmHeight*bm.bmWidthBytes,px); Hello World!

      C 1 Reply Last reply
      0
      • T twing

        maybe u can try this: unsigned char *px = new unsigned char[bm.bmHeight*bm.bmWidthBytes]; bitmap->GetBitmapBits(bm.bmHeight*bm.bmWidthBytes,px); Hello World!

        C Offline
        C Offline
        charmingzuo
        wrote on last edited by
        #3

        Thank twing. Why would you define the array data type as unsigned char? But you still present me a heuristic idea. The following method indeed works well. int size= bm.bmHeight*bm.bmWidthBytes; BYTE *px = new BYTE[size]; pBitmap->GetBitmapBits(size,px); Then, the array px stores the pixel value RGB, you can also use loop in +4 to get single R,G or B value, and use forced transform method, int ( px[i]) to get an int type value. Thanks, Ninaming :rose:

        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