Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The fastest way to save a graphic screen to disk using Qbasic

Graphical Techniques in QB

The fastest way to save a graphic screen to disk using Qbasic

by  Alt255  Posted    (Edited  )
By popular demand, here is your BSAVE and BLOAD programming example.
[tt]
'Set the graphics mode...
SCREEN 8 '640 x 200 Resolution
'Set up an array large enough to store the contents of the screen
REDIM GraphBlock(1 TO 31266)
'You determine the required size of the graphics array with:
'Bytes = 4 + INT(((X2-X1+1)*(Bits/pixel/plane)+7)/8)*planes*((Y2-Y1)+1)
'In SCREEN 8 that would be 62532 bytes for an array size of 31266.
'Draw a graphic....
X = 150: Y = 2
DO
CIRCLE (X, Y), Y / 4, (Y / 16) + 1
CIRCLE (X - Y, Y), Y / 4, (Y / 16) + 1
CIRCLE (X + Y, Y), Y / 4, (Y / 16) + 1
IF Y > 200 THEN EXIT DO
X = X + LOG(X * Y) / Y
Y = Y + LOG(Y) / 10
LOOP

'Place the contents of the screen in the array...
GET (0, 0)-(639, 199), GraphBlock
'Set the memory segment to first element of the array
DEF SEG = VARSEG(GraphBlock(1))
BSAVE "Screen.Img", VARPTR(GraphBlock(1)), 62532
'save it to a file
DEF SEG 'Reset the default memory segment to the Qbasic area
CLS 'To show that this actually works, clear the screen...
'and erase the array.
ERASE GraphBlock
PRINT "Press a key to load screen..."
DO WHILE INKEY$ = ""
LOOP
REDIM GraphBlock(1 TO 31266)
DEF SEG = VARSEG(GraphBlock(1))
BLOAD "Screen.Img", VARPTR(GraphBlock(1))
DEF SEG
PUT (0, 0), GraphBlock, PSET
[/tt]
The graphic has returned to the screen. A lot quicker the second time, eh?

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top