Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

bitmap

goldokhtargoldokhtar Posts: 4Member
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

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • goldokhtargoldokhtar Posts: 4Member
    : : 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: goldokhtar2007@yahoo.com
    well thanks again.
    bye...
  • zibadianzibadian Posts: 6,349Member
    : : : 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: goldokhtar2007@yahoo.com
    : 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"?
  • goldokhtargoldokhtar Posts: 4Member
    : : : : 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: goldokhtar2007@yahoo.com
    : : 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
  • zibadianzibadian Posts: 6,349Member
    : : : : : 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: goldokhtar2007@yahoo.com
    : : : 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.
    [code]
    type
    TBitmap = record
    Width, Height: word;
    Bitmap: array[0..63999] of byte;
    end;

    const
    HeaderID = 'PBM64';

    function LoadFromFile(const filename: string): TBitmap;
    var
    f: file;
    FileHeader: string;
    BM: TBitmap;
    begin
    Assign(f, filename);
    Reset(f, 1);
    BM.Width := 0;
    BM.Height := 0;
    if FileSize(f) <> SizeOf(TBitmap)+5 then
    begin
    FileHeader := ' ';
    BlockRead(f, FileHeader[1], 5);
    if FileHeader = HeaderID then
    BlockRead(f, BM, SizeOf(TBitmap));
    end;
    Close(f);
    LoadFromFile := BM;
    end;

    procedure SaveToFile(const filename: string; Bitmap: TBitmap);
    var
    f: file;
    begin
    Assign(f, filename);
    Rewrite(f, 1);
    BlockWrite(f, HeaderID[1], 5);
    BlockWrite(f, BM, SizeOf(TBitmap));
    Close(f);
    end;

    procedure DrawBitmap(X0, Y0: integer; Bitmap: TBitmap);
    var
    x, y: integer;
    begin
    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]);
    end;
    [/code]
    This code will not be compatible with existing bitmap-formats.
  • Phat NatPhat Nat Posts: 757Member
    : 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
    :

    Not sure how you're doing your graphics, but graphical screens are usually stored in memory at [$A000:0000]. Directly accessing the memory here is quick and easy, especially for a 320x200 256 color screen. Also, it is extremely easy for reading/writing BMP files.

    If your using say, 640x480 16 colors, it is a little more difficult as every byte in memory is now actually 2 pixels.

    So if you are in graphics mode 320x200x256 and you write:
    Mem[$A000:0000] := 15;
    This will make the Very Top-Left pixel White(Color 15)
    Mem[$A000:0001] := 14;
    This will make the second pixel from the left Yellow(Color 14)
    Now to make the next pixel down on the very left light-blue
    Mem[$A000:0320] := 11;
    since there are 320 pixels in a row.

    So what we can do, since we know there are 320 pixels per row is:
    Mem[$A000:x + y*320] := Color;
    where x & y are WORD values and COLOR is a BYTE

    Now a 320x200 8-bit (or 256 color) BMP is just one byte per pixel with a header. Just ignore the header and you get the picture.
    If you want to save, it's vise-versa, but you need to write a header.

    Here's a unit I put together ages ago for reading. Take a look at it:
    http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=16&MsgID=312573&Setting=A9999F0001

    Hope this gives you a start,
    Phat Nat

Sign In or Register to comment.