473,808 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(file Name,FileMode.O pen,FileAccess. Read);

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

Bitmap bitmap = (Bitmap)Image.F romFile(fileNam e);
int Bpheight = bitmap.Height;
int Bpwidth = bitmap.Width;

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

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

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 1150

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

Similar topics

1
3039
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 Bitmap(imgPhoto.Width,imgPhoto.Height,FileFormat); bitmap.HorizontalResolution=(float)Resolution.XPixelsInInch; bitmap.VerticalResolution=(float)Resolution.YPixelsInInch; Thanks.
2
11950
by: stephen fx | last post by:
Hello all! Using C/C++ I can do this: struct MyStruct { int a; char b; }; MyStruct test;
0
3611
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 into byte from a stream. Exception (System.ArgumentException: Invalid parameter used) occurs when reading from byte over a memory-stream back to the Bitmap object. Please help, I'm really stuck here! Here's the code I use (Sorry for a long...
9
11237
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. I wanted to use a regular expression but I could not find an ‘AND’ operator within the regular expression – so I need something like match true if string contains ‘a’ and ‘b’ and ‘c’ and ‘d’ ..etc,etc. If anyone has any thoughts on how I can...
3
1770
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 for a hydro plant. My boss would like me to create a web page so our control center can see all of the numbers but not have access to the actual form. Some of these numbers are gathered every second, others every five seconds and still others...
7
8246
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
9639
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 bitmap image.so please help me in doing this in c++. thank you.
2
1597
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 this? How can I read pixels under a form?
2
1216
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
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.