[comp.lang.pascal] Saving screen images to disk, can you help?

f0057@uafhp.uucp (James E. Ward) (08/07/89)

A few days ago, I posted a brief request for help in this newsgroup.  I guess
it was too brief!  What I need is techniques for saving screen images to disk
files using Turbo Pascal 5.0!  I am doing a bit of graphics/animation and need
to be able to save part of or all of the screen to disk.  Let me know if you
can help, okay?

James E. Ward
f0057@uafhp.uucp		Use this address or be bounced!

boc@druhi.ATT.COM (Ocinneide) (08/11/89)

In article <5425@decvax.dec.com>, f0057@uafhp.uucp (James E. Ward) writes:
> 
> 
> A few days ago, I posted a brief request for help in this newsgroup.  I guess
> it was too brief!  What I need is techniques for saving screen images to disk
> files using Turbo Pascal 5.0!  I am doing a bit of graphics/animation and need
> to be able to save part of or all of the screen to disk.  Let me know if you
> can help, okay?
> 
> James E. Ward
> f0057@uafhp.uucp		Use this address or be bounced!

The Graphic Screen Ram on a PC or Compatible starts at segment $B800. Once your image is being displayed on the screen you need to copy the appropriate memory segments to your file. I believe for CGA 4-Color Graphics mode you need to copy 16K bytes starting at this segment. Something like this should do it...

procedure saveimage(image_filespec:string);
var outfile:file;
begin
assign(outfile,image_filespec);
rewrite(outfile,16384);
blockwrite(outfile,ptr($B800,0)^,1);
close(outfile);
end;

To display your saved image again...

procedure showimage(image_filespec:string);
var infile:file;
begin
assign(infile,image_filespec);
reset(infile,16384);
blockread(infile,ptr($B800,0)^,1);
close(infile);
end;

These routines save and show the entire screen. To display a portion of the saved image requires more complex processing. The continuous bytes you have saved in the file represent screen pixel lines 1,3,5,7..199 followed by screen pixel lines 2,4,6,8..198,200. To pull a portion of the screen image for display then requires somewhat more complicated routines.... but heck! thats the fun of programming!
Good Luck!

Breanndan (AT&T An Rogha Cheart!)

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (08/21/89)

In article <4487@druhi.ATT.COM> boc@druhi.ATT.COM (Ocinneide) writes:
>In article <5425@decvax.dec.com>, f0057@uafhp.uucp (James E. Ward) writes:
>> 
>> 
>> A few days ago, I posted a brief request for help in this newsgroup.  I guess
>> it was too brief!  What I need is techniques for saving screen images to disk
>> files using Turbo Pascal 5.0!  I am doing a bit of graphics/animation and need
>> to be able to save part of or all of the screen to disk.  Let me know if you
>> can help, okay?
>> 
>> James E. Ward
>> f0057@uafhp.uucp		Use this address or be bounced!
>
>The Graphic Screen Ram on a PC or Compatible starts at segment $B800. Once your image is being displayed on the screen you need to copy the appropriate memory segments to your file. I believe for CGA 4-Color Graphics mode you need to copy 16K bytes start
i
>ng at this segment. Something like this should do it...

It's much safer to use Getimage and Putimage from the Graph unit.  They'll
work on any display that you have a BGI driver for, and can save any 
rectangular region on the screen.  (Well, almost any.  There was a bug that
made them ignore requests to save/restore a single line of pixels, but
it may have been fixed in 5.0 or 5.5.)  Be sure to use ImageSize to work
out how much space is needed; you can't just multiply rows by columns by depth
and get the right number.

To save to a file, just use BlockWrite after Getimage.

Duncan Murdoch