: : : : : how should i make a bitmap file with pascal??
: : : : : my project is to do a drawing and save it as a bitmap file..
: : : : : i also want to know how to load it too..thanks
: : : : :
: : : : A bitmap is nothing more than a header, telling the computer the filetype, size and possibly the palette; followed by the colors, 1 per pixel. If you want to make your bitmap compatible with other graphics programs, I suggest you read the format of the standard bmp-file. Otherwise you can simply store the graphic in a 2D-array and write that to file.
: : : :
: : :
: : : thanks for answering my question!!
: : : but could u send me an example in pascal that did the same with the graphic... the part u said store the graphic in a 2D-array...do u mean i put the pixel's color in a 2D-array??what should i say at the beginning when saving it in a file??file of ....???what are the records??
: : : my email is: firstname.lastname@example.org
: : : well thanks again.
: : : bye...
: : :
: : Indeed, I mean put the pixel's color value or color index to the palette in a 2D-array.
: : The header of a windows bitmap can be found here: http://en.wikipedia.org/wiki/Windows_bitmap
: : Other bitmap header formats can be found on the internet.
: : All bitmap files are binary files, you can make it an untyped file, or a file of byte (or char).
: : What do you mean by "what are the records"?
: hi...i still don't know how to do it...:(..couldn't figure it out...
: could u write the code for me please...a gaphic in pascal and want to save it as a bitmap file..thanks
Here is a simple method, which takes a maximum of 64000 pixels, in any width or length.
TBitmap = record
Width, Height: word;
Bitmap: array[0..63999] of byte;
HeaderID = 'PBM64';
function LoadFromFile(const filename: string): TBitmap;
BM.Width := 0;
BM.Height := 0;
if FileSize(f) <> SizeOf(TBitmap)+5 then
FileHeader := ' ';
BlockRead(f, FileHeader, 5);
if FileHeader = HeaderID then
BlockRead(f, BM, SizeOf(TBitmap));
LoadFromFile := BM;
procedure SaveToFile(const filename: string; Bitmap: TBitmap);
BlockWrite(f, HeaderID, 5);
BlockWrite(f, BM, SizeOf(TBitmap));
procedure DrawBitmap(X0, Y0: integer; Bitmap: TBitmap);
x, y: integer;
with Bitmap do
for y := 0 to Height-1 do
for x := 0 to Width-1 do
SetPixel(X0+x, Y0+y, Bitmap[x+y*Width]);
This code will not be compatible with existing bitmap-formats.