ThirtyTwoBit SUB - mkilgore/QB64pe GitHub Wiki
ThirtyTwoBit Screen Shot SUB for QB64 Screen and Image Handles
This SUB procedure can also be Included in a program!
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Syntax: ThirtyTwoBit left_column%, top_row%, right_column%, bottom_row%, handle&, new_filename$
- Copies portions or all of a Screen or image using the handle value to a new bitmap. SAVEIMAGE does full screen only!
- Make sure the maximum coordinates used are one less than the screen image's size or an Illegal Function call error will occur!
- A handle value of 0 will copy the present portion of the main program screen while the screen's handle may hold a previous image.
- Can be used with 4, 8 or 24/32 bit colors. 4 BPP = 16 colors, 8 BPP = 256 colors and 24/32 BPP has 16 million colors.
' ************************************** DEMO CODE **********************************
'
_TITLE "Demo of ThirtyTwoBit SUB by Ted Weissgerber 2010"
dst& = _NEWIMAGE(800, 600, 32) 'for console bitmap
SCREEN (statement) dst&
PAINT (799, 599), _RGB(180, 180, 180)
LINE (7, 15)-(648, 496), _RGB(0, 0, 80), BF
INPUT "Enter an image filename: ", filename$
bmp& = _LOADIMAGE(filename$, 256)
IF bmp& = -1 THEN BEEP: SYSTEM
bitmap& = _NEWIMAGE(_WIDTH (function)(bmp&), _HEIGHT(bmp&), 256)
_COPYPALETTE bmp&, bitmap& 'adopt image color settings
_PUTIMAGE , bmp&, bitmap& 'place bitmap in screen page
_DEST 0:
_PUTIMAGE (8, 16), bitmap& 'place screen page in console
'SAVEIMAGE 0, "Savedimage.bmp" ' get full screen image with Galleon's SAVEIMAGE SUB
x2% = (_WIDTH (function)(bmp&) - 1)
y2% = (_HEIGHT(bmp&) - 1)
ThirtyTwoBit 0, 0, x2%, y2%, bmp&, "BobSave.bmp" ' save actual image as BMP
' ********************** END DEMO *********************************
|
'****************************** Freeware by Bob Seguin *******************************
' Adapted for QB64 by Ted Weissgerber in 2010
'*************************************************************************************
[[SUB|SUB]] ThirtyTwoBit (x1%, y1%, x2%, y2%, image&, Filename$)
[[DIM|DIM]] Colors8%(255)
[[IF...THEN|IF]] x1% > x2% [[THEN|THEN]] [[SWAP|SWAP]] x1%, x2%
[[IF...THEN|IF]] y1% > y2% [[THEN|THEN]] [[SWAP|SWAP]] y1%, y2%
[[_SOURCE|_SOURCE]] image&
pixelbytes& = [[_PIXELSIZE|_PIXELSIZE]](image&)
[[IF...THEN|IF]] pixelbytes& = 0 [[THEN|THEN]] [[BEEP|BEEP]]: [[EXIT SUB|EXIT SUB]] 'no text screens
FileType$ = "BM"
QB64$ = "QB64" 'free advertiising in reserved bytes
[[IF...THEN|IF]] pixelbytes& = 1 [[THEN|THEN]] OffsetBITS& = 1078 [[ELSE|ELSE]] OffsetBITS& = 54 'no palette in 24/32 bit
InfoHEADER& = 40
PictureWidth& = (x2% - x1%) + 1
PictureDepth& = (y2% - y1%) + 1
NumPLANES% = 1
[[IF...THEN|IF]] pixelbytes& = 1 [[THEN|THEN]] BPP% = 8 [[ELSE|ELSE]] BPP% = 24
Compression& = 0
WidthPELS& = 3780
DepthPELS& = 3780
[[IF...THEN|IF]] pixelbytes& = 1 [[THEN|THEN]] 'byte padder prevents image skewing
NumColors& = 256 'set 256 colors even if they are not used by the screen mode
[[IF...THEN|IF]] (PictureWidth& [[MOD|MOD]] 4) [[THEN|THEN]] ZeroPad$ = [[SPACE$|SPACE$]](4 - (PictureWidth& [[MOD|MOD]] 4))
[[ELSE|ELSE]] '24/32 bit images use 3 bytes for RGB pixel values
NumColors& = 0 '24/32 bit say zero
[[IF...THEN|IF]] ((PictureWidth& * 3) [[MOD|MOD]] 4) [[THEN|THEN]] ZeroPad$ = [[SPACE$|SPACE$]]((4 - ((PictureWidth& * 3) [[MOD|MOD]] 4)))
[[END IF|END IF]]
ImageSize& = (PictureWidth& + [[LEN|LEN]](ZeroPad$)) * PictureDepth&
FileSize& = ImageSize& + OffsetBITS&
f = [[FREEFILE|FREEFILE]]
[[OPEN|OPEN]] Filename$ [[FOR...NEXT|FOR]] [[BINARY|BINARY]] [[AS|AS]] #f
[[PUT|PUT]] #f, , FileType$
[[PUT|PUT]] #f, , FileSize&
[[PUT|PUT]] #f, , QB64$
[[PUT|PUT]] #f, , OffsetBITS&
[[PUT|PUT]] #f, , InfoHEADER&
[[PUT|PUT]] #f, , PictureWidth&
[[PUT|PUT]] #f, , PictureDepth&
[[PUT|PUT]] #f, , NumPLANES%
[[PUT|PUT]] #f, , BPP%
[[PUT|PUT]] #f, , Compression&
[[PUT|PUT]] #f, , ImageSize&
[[PUT|PUT]] #f, , WidthPELS&
[[PUT|PUT]] #f, , DepthPELS&
[[PUT|PUT]] #f, , NumColors&
[[PUT|PUT]] #f, , SigColors& '51 offset
[[IF...THEN|IF]] pixelbytes& = 1 [[THEN|THEN]] '4 or 8 BPP use 256 color Palette
u$ = [[CHR$|CHR$]](0)
[[FOR...NEXT|FOR]] c& = 0 [[TO|TO]] 255 [[PUT|<span style="color:blue;">PUT</span>]] as BGR order colors
cv& = [[_PALETTECOLOR (function)|_PALETTECOLOR]](c&, image&)
Colr$ = [[CHR$|CHR$]]([[_BLUE32|_BLUE32]](cv&))
[[PUT|PUT]] #f, , Colr$
Colr$ = [[CHR$|CHR$]]([[_GREEN32|_GREEN32]](cv&))
[[PUT|PUT]] #f, , Colr$
Colr$ = [[CHR$|CHR$]]([[_RED32|_RED32]](cv&))
[[PUT|PUT]] #f, , Colr$
[[PUT|PUT]] #f, , u$ 'Unused byte
[[NEXT|NEXT]]
[[END IF|END IF]]
[[FOR...NEXT|FOR]] y% = y2% [[TO|TO]] y1% [[STEP|STEP]] -1 'place bottom up
[[FOR...NEXT|FOR]] x% = x1% [[TO|TO]] x2%
c& = [[POINT|POINT]](x%, y%)
[[IF...THEN|IF]] pixelbytes& = 1 [[THEN|THEN]]
a$ = [[CHR$|CHR$]](c&)
Colors8%(c&) = 1
[[ELSE|ELSE]]: a$ = [[LEFT$|LEFT$]]([[MKL$|MKL$]](c&), 3)
[[END IF|END IF]]
[[PUT|PUT]] #f, , a$
[[NEXT|NEXT]]
[[PUT|PUT]] #f, , ZeroPad$
[[NEXT|NEXT]]
[[FOR...NEXT|FOR]] n = 0 [[TO|TO]] 255
[[IF...THEN|IF]] Colors8%(n) = 1 [[THEN|THEN]] SigColors& = SigColors& + 1
[[NEXT|NEXT]] n
[[PUT|PUT]] #f, 51, SigColors&
[[CLOSE|CLOSE]] #f
[[END SUB|END SUB]] '' ''
|
See also:
SAVEIMAGE (Full image bitmaps)
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page