Solved

extracting RGB values from BMP

Posted on 2003-12-11
6
731 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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