Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14007

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
bitmap Posted by goldokhtar on 6 Feb 2007 at 2:22 PM
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
Report
Re: bitmap Posted by zibadian on 6 Feb 2007 at 7:35 PM
: 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.
Report
Re: bitmap Posted by goldokhtar on 7 Feb 2007 at 6:10 AM
: : 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...
Report
Re: bitmap Posted by zibadian on 7 Feb 2007 at 6:16 AM
: : : 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"?
Report
Re: bitmap Posted by goldokhtar on 9 Feb 2007 at 9:02 AM
: : : : 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
Report
Re: bitmap Posted by zibadian on 9 Feb 2007 at 1:45 PM
: : : : : 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.
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;

This code will not be compatible with existing bitmap-formats.
Report
Re: bitmap Posted by Phat Nat on 9 Feb 2007 at 11:39 PM
: 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 <DOS> 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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.