473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to read every bit ina bitmap

Ok i had a method for finding the colours in a bitmap file but its very
inefficient so i will have to go through each bit individually and check
its value. I will have to go through the bytes in the file first i have
the bytes read in........i should only be getting a black and white
value either 255 or 0 but i am getting these other values like 66 in the
byte array........

input = new FileStream(fileName,FileMode.Open,FileAccess.Read) ;

binaryData = new Byte[input.Length];
long bytesRead = input.Read(binaryData, 0,
(int)input.Length);

Bitmap bitmap = (Bitmap)Image.FromFile(fileName);
int Bpheight = bitmap.Height;
int Bpwidth = bitmap.Width;

int widthinbytes = (Bpwidth + 7) /8;
int padding = widthinbytes %4;
for (int biheight=0;biheight < Bpheight;biheight++)
{
for (int width=0; width < widthinbytes; width++)

{
//scan through each bit in a byte
for( int bitpos =7; bitpos >= 0;bitpos--)
{
current_byte_position = (biheight *(widthinbytes + padding)) + width;
int Is_Set = bitvalue(bitpos,binaryData[current_byte_position]);
}
}
}

int bitvalue(int index,byte datarray)
{
byte[] masks = new byte[8];

byte temp = 0x01;

for (int i = 0; i <=7;i++)
{
masks[i] = temp;
temp <<= 1;
}

return(datarray & masks[index])>>index;
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
0 1127

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Olaf Baeyens | last post by:
To my big suprise HorizontalResolution and VerticalResolution iof the Bitmap class are read-only! Is there any reason to this? And How do I change them? Bitmap bitmap = new...
2
by: stephen fx | last post by:
Hello all! Using C/C++ I can do this: struct MyStruct { int a; char b; }; MyStruct test;
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
9
by: booksnore | last post by:
I am writing some code to search for strings that contain every letter of the alphabet. At the moment I am using the method below to check to see if a string contains every letter of the alphabet....
3
by: Dave | last post by:
Hey all, I have a problem and I can't find anything on the net to really address it. We have a program at work that has lots of numbers on the front of the form because it is a control program...
7
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
2
by: ajay_itbhu | last post by:
Hi everyone, I want to read the pixel values of 2 similar images in bitmap format like 2 continuous frame of a video for calculating the median. But i dont know how to read the pixel values of...
2
by: MrAsm | last post by:
Hi, I would like to create a form and read the pixels of the layer under my form (think of a kind of magnifier glass), to do some processing on them. Do you have any idea about how to do...
2
by: Samuel | last post by:
Hi I would like to read a specified rectangle from an existing bitmap and draw it in another. Thank you, Samuel
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.