Click here to Skip to main content
14,387,866 members
Rate this:
Please Sign up or sign in to vote.
See more:
How can i read pixels of bmp image format ? i have used fread function but i have got meaningless should i read it correctly?
what is the header size that i should skip it ?
and i want to know , when you open a bmp image by notepad++ ,what is the output ? why can not read an image information, by this program (notepad++) ?
Updated 9-Mar-14 1:25am
Kornfeld Eliyahu Peter 9-Mar-14 6:24am
You question is a bit confusing...
You may consider to improve it and may add your current code for examination (sometimes people with experience understood code better than words)...

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Bitmap files are not Notepad compatible, and aren't just a block of simple data either.

Bitmap files are stored as binary data, not characters and are not intended to be human readable. When you open it with any text-type editor application, if you are lucky you will get a (pretty meaningless) hexadecimal display. If you are unlucky, you will get a display full of odd shaped blobs and question marks for the most part.

You can read a bitmap file directly into your program, as a sequence of bytes - but unless you process those bytes correctly, it still isn't going to make much sense; there is more in there than just the pixels. Wikipedia[^] explains it pretty well.

There is an easier way: read the BMP file as an image and let existing code handle the file format: it will then present you with data and (normally, depending on the system) functions to access and manipulate the image data on a pixel basis if needs be.

I have no idea what language you are using, or system you are building for, so I can't help you any further - but start looking for an image class or function and start from there.
Kornfeld Eliyahu Peter 9-Mar-14 6:41am
No doubt, be a native English helps you lot - I was unable to understand what he really talking about :-)
OriginalGriff 9-Mar-14 7:03am
Not as much as you would hope, with some questions.... :sigh:
Kasrajj 9-Mar-14 14:36pm
iam using c++.first i opened my file by function: ifstream file1 = ifstream("C:/Users/lenovo/Desktop/A Frenchman weeps.bmp",ios::beg) and then i use,1000); (a is char array). i want the RGB of each pixel by 3 integer but i donot know how to get it.
OriginalGriff 9-Mar-14 14:48pm
First off, you need unsigned char, or byte, not char - you don't want any translation, or sign, and BMP data is fully eight bit.

Secondly, as I said, it's not that simple. If you want to go that route, then you need to start reading the wiki link I gave you as there is a lot of other data you need to extract just to locate the right pixel data!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100