1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
void SaveImage(const char* filename)
{
int Width = 470;
int Height = 470;
FILE *f;
unsigned char *img = NULL;
int triple_area = 3*Width*Height;
if(img) free(img);
img = (unsigned char *)malloc(triple_area);
memset(img,0,sizeof(img));
int res;
Assign_Bitmap_Req(triple_area); //Sets up BmpFileHeader, BmpInfoHeader, BmpPadding as unsigned char arrays
for(int i=0; i<Width; i++)
{
for(int j=0; j<Height; j++)
{
res = Height - 1 - j;
img[(i+res*Width)*3+2] = (unsigned char)(100);
img[(i+res*Width)*3+1] = (unsigned char)(100);
img[(i+res*Width)*3+0] = (unsigned char)(100);
}
}
f = fopen(filename,"wb");
fwrite(BmpFileHeader,1,14,f);
fwrite(BmpInfoHeader,1,40,f);
int remainder = (4-(Width*3)%4)%4;
for(int i=0; i<Height; i++)
{
fwrite(img+(Width*(Height-i-1)*3),3,Width,f);
fwrite(BmpPadding,1,remainder,f);
}
fclose(f);
}
|