Solved

extracting RGB values from BMP

Posted on 2003-12-11
6
714 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
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 50 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 45
deburging in oracle form 12 76
twoTwo  challenge 35 86
scoreUp challenge 14 48
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now