?
Solved

extracting RGB values from BMP

Posted on 2003-12-11
6
Medium Priority
?
736 Views
Last Modified: 2013-11-20
Hello people
newbie here well i have displayed a BMP image using CBitmap HBITMAP and BITMAP I am using MFC ofcourse and would like to manipulate the actual pixel values that is the RGB values but i am finding it extremely difficult to get the RGB values please help me out how to get the RGB values for a BMP image
0
Comment
Question by:cyberizen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 200 total points
ID: 9926483
Put your bitmap into a DC

CDC* pDC=GetDC();
    CDC MemDC;
    MemDC.CreateCompatibleDC(pDC);
    CBitmap* pOldBitmap = MemDC.SelectObject(&m_bitmap);

MemDC.GetPixel(x,y); returns the RGB of the pixel at x,y


RELEASE THE DC WHEN FINISHED
ReleaseDC(pDC);
0
 

Expert Comment

by:MAYURNATH
ID: 9972131
My opinion about the bytes to extract is :


BITMAP FILE Contains :

BITMAPFILEHEADER
BITMAPINFOHEADER
COLORTABLE
BYTES OF THE BITMAP DATA


4 aspects are serailly placed in bitmap file OK.

BITMAPINFOHEADER tells about the bitmap type - 16 colors ( 4 bit ) (0.5 bytes ) , 256 colors ( 8 bit ) (1 byte ) , 24 bit ( 3 bytes ).

Colortable explains the table of colors that exists in bitmap data. - RGB values ( Here RGB is RGBQUAD - 4 bytes )

according to the color type using the color table we can get RGB value .

for 16 colors ( 4 bit ) (1/2 byte) - first half byte in bytes of bitmap  data represent the index of the color in color table.
with this index u have to get the color from the color table.
ex. let us take first byte is 0xBA - 10111010 (binary ) then 2 colors in 4 bit type , u get 0xB and 0xA ie. 11 and 10.
then u go for 11 and 10 indices of color table and get the RGB color.

if it is 256 colors in above example 0xBA - 186 index. in 256 colors color table contains 256 colors.
so go for 186 index and get the corresponding RGB value.


in the case of  24 bit - 3 bytes which will directly give RGB value.
ie no color table concept in 24 bit type bitmap.
directly 3 bytes on pixel so R,G,B - 3 bytes u get.

i think this is clear about the bmp file format and bitmap format.

My opinion is write the bit handling code - because it will be faster and easy for modification once written.
The above solution is good but to setpixel it will take lot of time if u try for more than 80X80 pixel bmp .

thanx
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11850729
My comment would be a way to achieve the desired effect
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question