Męczę się ze stworzeniem pliku BMP. Plik się tworzy, mniej więcej jest rozmiar odpowiedni, ale nie da się go wyświetlić. Podejrzewam coś z nagłówkiem, bo chociaż nie widzę błędu ma on jakimś cudem 56 bajtów. Proszę o jakieś sugestie, oto kod:
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
struct bmp_header
{
unsigned short int bfType;
unsigned long int bfSize;
unsigned long int bfReserved;
unsigned long int bfOffBits;
unsigned long int biSize;
unsigned long int biWidth;
unsigned long int biHeight;
unsigned short int biPlanes;
unsigned short int biBitCount;
unsigned long int biCompression;
unsigned long int biSizeImage;
unsigned long int biXPelsPerMeter;
unsigned long int biYPelsPerMeter;
unsigned long int biClrUsed;
unsigned long int biClrImportant;
};
bmp_header b;
int main()
{
srand(time(0));
const int x=800;
const int y=800;
FILE *fp=fopen("obraz.bmp", "wb");
b.bfType=19778;
b.bfSize=54+x*y*4;
b.bfOffBits=1078;
b.biSize=40;
b.biWidth=x;
b.biHeight=y;
b.biPlanes=1;
b.biBitCount=24;
fwrite((char*)&b,1,sizeof(bmp_header), fp);
for(int tx=0; tx<x;tx++)
{
for(int ty=0; ty<y;ty++)
{
static unsigned char color[3];
color[0]=tx%255;
color[1]=ty%255;
color[2]=(tx*ty)%255;
fwrite(color, 1, 3, fp);
}
}
fclose(fp);
}