for a school project, we have in a certain function read pixels from a binary file, which is a BMP format. pixels is a 2D array of Pixel type from an object. The goal here is to read from the binary file X lines and Y columns of pixels. However, there is some padding after each line of pixels, which can be calculated with the function calculatePadding(), which has a return type of unsigned.
What we have to do is read line by line the file in binary and skip the padding after each line, as we are storing the pixels in another variable. This is what I did so far:
for (int i = image.height - 1; i >= 0; i--) {
for (unsigned j = 0;j < image.width; j++) {
file.read((char*)&image.pixels[i][j], sizeof(Pixel));
}
fichier.seekg(sizeof(calculatePadding(image)) + tellp() , ios::beg);
}
My problem is with the last line(before the last closing bracket). I know I have to set the cursor forward by adding the current position of the cursor and whatever size the padding takes. However, how can I add an unsigned and streampos? I don't understand what conversion I should make. We are not allowed to use ignore()
Thank you for any help!
Also, on a side note, how can you write '0's to a binary file? On the next function, I have to take an image and write it in a binary file and put '0's in binary where there is padding.
Is this something that works?
int zero = 0;
file.write((char*)&zero, sizeof(calculatePadding(image)));