Because BMP files are written from bottom to top (in terms of pixels), I need to read a BMP file in reverse (and get rid of the 54-byte header). My code so far:
public string createNoHeaderBMP(string curBMP) //copies everything but the header from the curBMP to the tempBMP
{
string tempBMP = "C:\\TEMP.bmp";
Stream inStream = File.OpenRead(curBMP);
BinaryReader br = new BinaryReader(inStream);
byte[] fullBMP = new byte[(width * height * 3) + 138];
byte[] buffer = new Byte[1];
long bytesRead;
long totalBytes = 0;
while ((bytesRead = br.Read(buffer, 0, 1)) > 0)
{
fullBMP[fullBMP.Length - 1 - totalBytes] = buffer[0];
totalBytes++;
}
FileStream fs = new FileStream(tempBMP, FileMode.Create, FileAccess.Write);
fs.Write(fullBMP, 54, fullBMP.Length - 54);
fs.Close();
fs.Dispose();
return tempBMP;
}
for some reason it fails to do the job completely, and this results in an image with part of the right side placed on the left. Why isn't it completely reversing the file? Also, these BMP files are very large (600MB), so I can't use a simple memorystream and do a seek and swap operation because I'll get the "Out of Memory" exception.