[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

extracting RGB values from BMP

Posted on 2003-12-11
6
Medium Priority
?
738 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 45

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 45

Expert Comment

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

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 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