I'm pretty much a beginner when it comes to programming and have only recently started learning C++. Right now I'm stuck trying to covert a bitmap into a binary array. This is for a Robotics competition I've entered. The bitmap is a 54*96 pixel monochromatic 1 bpp image. I'm confused with the offset positions while trying to read the header. This is the code I've written so far and would greatly appreciate any help. I think the error lies in increment of the lineNo variable which needs to be in hex, but how to increment such values?
What I want to ultimately achieve is to read only some parts of the bitmap particularly the boxes with cross on them (see image below). How do I find out the pixel locations?
#include <SD.h>
#include <SPI.h>
File bMap;
File Text;
void setup()
{
Serial.begin(9600);
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
int height = 0;
int width = 0;
int bitmapOffset = 0xa;
bMap = SD.open("map.bmp", FILE_READ);
Text = SD.open("test.txt", FILE_WRITE);
\\bMap.seek(0xa);
\\bitmapOffset = bMap.read();
\\Serial.println(bitmapOffset, BIN);
\\Serial.println(bMap, HEX);
bMap.seek(0x16);
for (int i = 0; i < 4; i++) {
height += (bMap.read() << (8 * i));
Serial.println(height);
int lineNo;
int fileposition = 0;
for (lineNo = 0; lineNo < height; lineNo++)
fileposition = bitmapOffset + (lineNo);
bMap.seek(fileposition);
//Serial.print(lineNo);
Serial.print(fileposition);
//Serial.print(bitmapOffset);
}
bMap.seek(0x12);
for (int i = 0; i < 4; i++) {
width += (bMap.read() << (8 * i));
Serial.println(width);
if (Text) {
Text.println(height, width);
Text.close();
}
}
}
void loop() {}
