You should study the
BMP file format[
^] if you want to do the whole thing "by hand". Looking at your code i'd say:
-note that not every BMP is 24 bits per pixel, that is, 1 byte for red, 1 byte for green and 1 byte for blue.
-note that this:
pixeldata = new PIXEL[width - 1, height - 1 ];
does not allocate a buffer of (width - 1) by (height - 1) PIXEL structures, what you probably want here is:
pixeldata = new PIXEL[(width - 1) * (height - 1)];
and then, why minus one? Shouldn't it be
pixeldata = new PIXEL[width * height]
?