How to get pixel value in BITMAP?
-
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
-
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
-
maybe u can try this: unsigned char *px = new unsigned char[bm.bmHeight*bm.bmWidthBytes]; bitmap->GetBitmapBits(bm.bmHeight*bm.bmWidthBytes,px); Hello World!
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: