started writing this today; still new too writing files though. it's not working yet, the program runs and executes with out crashing but the file it creates can't be opened so i think i must have messed up the file header some where. It will be neat too get this working, with direct access to pixel data i am sure there are a lot of cool designs that can be created. I haven't really started de-buging it yet, wouldn't be surprised if it had an obvious problem.
Code:
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#define BI_RGB 0x00000000;
typedef unsigned char byte;
struct fileheaderstruct{
unsigned short bftype; // must be 19778
unsigned int bfsize; // size of file in bytes
unsigned short bfreserved1; // reserved, must equal zero
unsigned short bfreserved2; // reserved must equal zero
unsigned int bfoffbits; // offset from fileheader to pixel array
};
struct infoheaderstruct{
unsigned int bisize; // size of infoheader in bytes
unsigned int biwidth; //width in pixels
unsigned int biheight; //hieght in pixels
unsigned short biplanes; //number of bit map planes
unsigned short bibitcount; // bits per pixel (4, 8, 24)
unsigned int bicompresion; //compression used; BI_RGB no compression, BI_RL4, BI_RLE8
unsigned int bisizeimage; //size of bitmap image storage
unsigned int bixpelspermeter; //horizontal resolution of target device
unsigned int biypelspermeter; //vertical resolution of target device
unsigned int biclrused; //colors used, if zero reading uses max colors allowed by bibitcount
unsigned int biclrimportant; //colors important, if zero all colors are important
};
struct RGBquadstruct{ // color pallet structure
byte red; // intinsity of red, 0- 255
byte blue; // intensity of blue, 0- 255
byte green; // intensity of green, 0- 255
byte reserved; // reserved, must be equal to zero
};
struct pixel24struct{
byte red;
byte green;
byte blue;
};
int main()
{
int high;
int length;
struct bitmap24struct{ // defines truecolor bit map, no color pallet 1080x1920
struct fileheaderstruct fileheader;
struct infoheaderstruct infoheader;
struct pixel24struct pixel[1080][1920];
};
bitmap24struct *bitmapfile;
bitmapfile = (struct bitmap24struct*)malloc(sizeof(struct bitmap24struct));
if(bitmapfile == NULL)
{
printf("\n****************memory allocation error*********************\n");
getch();
return 0;
}
bitmapfile->fileheader.bftype = 19778;
bitmapfile->fileheader.bfsize = sizeof(struct bitmap24struct);
bitmapfile->fileheader.bfreserved2 = 0;
bitmapfile->fileheader.bfreserved1 = 0;
bitmapfile->fileheader.bfoffbits = sizeof(struct infoheaderstruct);
bitmapfile->infoheader.biheight = 1080;
bitmapfile->infoheader.biwidth = 1920;
bitmapfile->infoheader.biclrused = 0;
bitmapfile->infoheader.biclrimportant = 0;
bitmapfile->infoheader.bibitcount = 24;
bitmapfile->infoheader.bisizeimage = 6220800;
bitmapfile->infoheader.bicompresion = BI_RGB;
bitmapfile->infoheader.biypelspermeter = 0;
bitmapfile->infoheader.bixpelspermeter = 0;
bitmapfile->infoheader.bisize = sizeof(struct infoheaderstruct);
bitmapfile->infoheader.biplanes = 1;
high = 0;
while( high < 1080)
{
length = 0;
while(length < 1920)
{
bitmapfile->pixel[high][length].red = 128;
bitmapfile->pixel[high][length].green = 128;
bitmapfile->pixel[high][length].blue = 128;
length++;
}
high++;
}
fwrite(bitmapfile, 1, sizeof(struct bitmap24struct), fopen("mypicture.bmp", "w"));
return 0;
}