Screenshots in QB or DOS

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
coma8coma1
Veteran
Posts: 100
Joined: Sat Dec 08, 2007 5:29 pm
Location: Maryland, USA

Screenshots in QB or DOS

Post by coma8coma1 »

I've always been able to take screenshots of my QB games in screen 13 by hitting the Print Screen key and then opening pbrush and hitting Ctrl+V. For instance, my character from DSQ is my avatar and I captured him on an old Compaq running Win95 years ago.

This machine, running WinXP doesn't let me. I've tried several screen shot programs as well and none seem to work. What am I doing wrong??
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Try this SUB procedure for Screen 13 that creates a bitmap screenshot:

Code: Select all

SUB EightBIT (x1%, y1%, x2%, y2%, Filename$)   'SCREEN 13 bitmap maker
                                                 'takes 1 second fullscreen
  DIM FileCOLORS%(1 TO 768)
  DIM Colors8%(255)

  IF INSTR(Filename$, ".BMP") = 0 THEN
    Filename$ = RTRIM$(LEFT$(Filename$, 8)) + ".BMP"
  END IF

  FileTYPE$ = "BM"
  Reserved1% = 0
  Reserved2% = 0
  OffsetBITS& = 1078
  InfoHEADER& = 40
  PictureWIDTH& = (x2% - x1%) + 1
  PictureDEPTH& = (y2% - y1%) + 1
  NumPLANES% = 1
  BPP% = 8
  Compression& = 0
  WidthPELS& = 3780
  DepthPELS& = 3780
  NumCOLORS& = 256

  IF PictureWIDTH& MOD 4 <> 0 THEN
  ZeroPAD$ = SPACE$(4 - PictureWIDTH& MOD 4)
  END IF

  ImageSIZE& = (PictureWIDTH& + LEN(ZeroPAD$)) * PictureDEPTH&
  FileSize& = ImageSIZE& + OffsetBITS&

  OUT &H3C7, 0
  FOR n = 1 TO 768 STEP 3
    FileCOLORS%(n) = INP(&H3C9)
    FileCOLORS%(n + 1) = INP(&H3C9)
    FileCOLORS%(n + 2) = INP(&H3C9)
  NEXT n

  OPEN Filename$ FOR BINARY AS #1

  PUT #1, , FileTYPE$
  PUT #1, , FileSize&
  PUT #1, , Reserved1% 'should be zero
  PUT #1, , Reserved2% 'should be zero
  PUT #1, , OffsetBITS&
  PUT #1, , InfoHEADER&
  PUT #1, , PictureWIDTH&
  PUT #1, , PictureDEPTH&
  PUT #1, , NumPLANES%
  PUT #1, , BPP%
  PUT #1, , Compression&
  PUT #1, , ImageSIZE&
  PUT #1, , WidthPELS&
  PUT #1, , DepthPELS&
  PUT #1, , NumCOLORS&
  PUT #1, , SigCOLORS&     '51 to 54

  u$ = " "
  FOR n% = 1 TO 768 STEP 3  'PUT as BGR order colors
    Colr$ = CHR$(FileCOLORS%(n% + 2) * 4)
    PUT #1, , Colr$
    Colr$ = CHR$(FileCOLORS%(n% + 1) * 4)
    PUT #1, , Colr$
    Colr$ = CHR$(FileCOLORS%(n%) * 4)
    PUT #1, , Colr$
    PUT #1, , u$ 'Unused byte
  NEXT n%

  FOR y = y2% TO y1% STEP -1   'place bottom up
    FOR x = x1% TO x2%
      a$ = CHR$(POINT(x, y))
      Colors8%(ASC(a$)) = 1
      PUT #1, , a$
    NEXT x
    PUT #1, , ZeroPAD$
  NEXT y

  FOR n = 0 TO 255
    IF Colors8%(n) = 1 THEN SigCOLORS& = SigCOLORS& + 1
  NEXT n

  PUT #1, 51, SigCOLORS&

  CLOSE #1

END SUB
Code adapted from a routine by Bob Seguin.

In your MAIN module SUB call:

You can use a certain keypress to trigger a snapshot of the screen.

The filename can just be the first name as SUB will add ".BMP" if needed. You could also add a snapshot number to the name for more bitmaps. Screen 13 does it pretty fast.

x1 and x2 can be from 0 to 319, y1 and y2 from 0 to 199 respectively.

I also have a SUB for SCREEN 12 that may take up to 8 seconds to create a fullscreen snapshot.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
coma8coma1
Veteran
Posts: 100
Joined: Sat Dec 08, 2007 5:29 pm
Location: Maryland, USA

Post by coma8coma1 »

oh man that's great! I'll give it try later and then maybe I can post some better screen shots of my project I'm working on. Right now the only recent screenshots I have were done with a digital camera where I took pictures of the screen! lol

thanks again. i'll give it a try later tonight or tomorrow. :)
Post Reply