vbdpss.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Article Q50225
                                                 Contents  Index  Back
─────────────────────────────────────────────────────────────────────────────
                           Knowledge Base Contents  Knowledge Base Index
 
 How to Convert VGA Colors to Their Equivalent Gray Scale - Q50225
 
 In Microsoft Visual Basic version 1.0 for MS-DOS, VGA colors can be
 converted to their equivalent gray scale values using the
 CALL INTERRUPT statement. This can be useful when printing an image
 or having the image scanned by devices that do not support color.
 
 This procedure can be used to convert a color image to a monochrome
 equivalent before printing out the image on a dot-matrix printer.
 
 Once the color registers are converted to their gray scale
 equivalents, the original red, green, and blue values are lost. If
 this information needs to be restored, the VGA color registers should
 be saved before doing the gray scale summing, and then restored
 afterward.
 
 More Information:
 
 The following program is GRAY.BAS, which displays a multicolored
 image in VGA SCREEN 13, then converts all of the colors to their
 equivalent gray scale values:
 
 Example
 -------
 
 ' To run this program in the environment, you must invoke the
 ' environment with the /L switch to load the default Quick library:
 '    VBDOS.EXE /L              for Visual Basic 1.0 for MS-DOS
 ' To try this example in VBDOS.EXE:
 ' 1. From the File menu, choose New Project.
 ' 2. Copy the code example to the Code window.
 ' 3. Press F5 to run the program.
 ' Use the following include file for Visual Basic 1.0 for MS-DOS:
 REM $INCLUDE: 'VBDOS.BI'
 
 DIM inregs AS RegType
 DIM outregs AS RegType
 SCREEN 13
 
 FOR i% = 2 TO 255      ' Display colorful pattern.
         LINE (i%, 10)-(i%, 199), i%
 NEXT
 
 LOCATE 1, 1
 COLOR 7
 PRINT "press any key to convert to gray scale"
 WHILE INKEY$ = "": WEND
 
 inregs.ax = &H101B     ' ROM BIOS call to set gray scale values.
 inregs.bx = 0          ' Start at color register 0.
 inregs.cx = 256        ' Convert all 256 color registers.
 CALL INTERRUPT(&H10, inregs, outregs)
 
 LOCATE 1, 1
 PRINT "press any key to end                   "
 WHILE INKEY$ = "": WEND
 END
 
 To demonstrate this program as an .EXE program, compile and link as
 follows:
 
    BC GRAY.BAS;
    LINK GRAY,,,VBDOS.LIB;