Answer to Question #5837 in C# for Mariyah
i want to read bitmap file with binary reader,without using bitmap class, and then convert it into gray scale
As we have understood you need to convert image in byte form to gray scale also in byte form.
See code snippets
//Open file into a filestream and
//read data in a byte array.
byte ReadFile(string sPath)
//Initialize byte array with a null value initially.
byte data = null;
//Use FileInfo object to get file size.
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
//Open FileStream to read file
FileStream fStream = new FileStream(sPath, FileMode.Open,
//Use BinaryReader to read file stream into byte array.
BinaryReader br = new BinaryReader(fStream);
//When you use BinaryReader, you need to
//supply number of bytes to read from file.
//In this case we want to read entire file.
//So supplying total number of bytes.
data = br.ReadBytes((int)numBytes);
//Once you have image byte array
//you transform to gray scale like this
byte TransformToGrayscale(byte imageArr)
byte result = new byte[imageArr.Length];
result[i] = (byte)(imageArr[i] >> 8);
Learn more about our help with Assignments: C#