Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <wingdi.h>
- int main() {
- FILE* bmp = fopen("pic.bmp", "rb");
- BITMAPFILEHEADER bfh;
- BITMAPINFOHEADER bih;
- fread(&bfh, sizeof(bfh), 1, bmp);
- fread(&bih, sizeof(bfh), 1, bmp);
- fseek(bmp, bfh.bfOffBits, SEEK_SET);
- int bits = 0;
- int width;
- if (bih.biWidth % 8 == 0) {
- width = bih.biWidth + ((bih.biWidth / 8) % 4) * 8;
- }
- else {
- width = (bih.biWidth / 8 + 1) * 8 + (4 - ((bih.biWidth / 8 + 1) % 4)) * 8;
- }
- int map[bih.biHeight][bih.biWidth];
- for (int i = bih.biHeight - 1; i >= 0; i--) {
- for (int j = 0; j < width; j += 8) {
- char ch = fgetc(bmp);
- for (int k = 7; k >= 0; k--) {
- map[i][7 - k + j] = ((ch >> k) & 1);
- bits++;
- printf("%i", map[i][k + j]);
- }
- }
- }
- printf("\n%i %i %i", bits, bih.biHeight, width);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement