ThirtyTwoBit MEM SUB - mkilgore/QB64pe GitHub Wiki
Fast Bitmap Export routine using memory for use with 32-bit color images ONLY
Code by Steve McNeill
SUB for 32 BIT COLOR IMAGES ONLY!
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
picture& = _SCREENIMAGE x1% = 0: y1% = 0 x2% = _WIDTH (function)(picture&) - 1 y2% = _HEIGHT(picture&) - 1 SaveBMP32 x1%, x2%, y1%, y2%, picture&, "ScreenShot.bmp" '' '' |
[[TYPE|TYPE]] BMPFormat ' Description Bytes QB64 Function ID [[AS|AS]] [[STRING|STRING]] * 2 'File ID("BM" or 19778 [[AS|AS]] Integer) 2 [[CVI|CVI]]("BM") Size [[AS|AS]] [[LONG|LONG]] ' Total Size of the file 4 LOF Blank [[AS|AS]] [[LONG|LONG]] ' Reserved 4 Offset [[AS|AS]] [[LONG|LONG]] ' Start offset of image pixel data 4 (add one for GET) Hsize [[AS|AS]] [[LONG|LONG]] ' Info header size (always 40) 4 PWidth [[AS|AS]] [[LONG|LONG]] ' Image width 4 [[_WIDTH (function)|_WIDTH]](handle&) PDepth [[AS|AS]] [[LONG|LONG]] ' Image height (doubled in icons) 4 [[_HEIGHT|_HEIGHT]](handle&) Planes [[AS|AS]] [[INTEGER|INTEGER]] ' Number of planes (normally 1) 2 BPP [[AS|AS]] [[INTEGER|INTEGER]] 'Bits per pixel(palette 1, 4, 8, 24) 2 [[_PIXELSIZE|_PIXELSIZE]](handle&) Compression [[AS|AS]] [[LONG|LONG]] ' Compression type(normally 0) 4 ImageBytes [[AS|AS]] [[LONG|LONG]] ' (Width + padder) * Height 4 Xres [[AS|AS]] [[LONG|LONG]] ' Width in PELS per metre(normally 0) 4 Yres [[AS|AS]] [[LONG|LONG]] ' Depth in PELS per metre(normally 0) 4 NumColors [[AS|AS]] [[LONG|LONG]] ' Number of Colors(normally 0) 4 2 ^ BPP SigColors [[AS|AS]] [[LONG|LONG]] ' Significant Colors(normally 0) 4 [[END|END]] [[TYPE|TYPE]] ' ' Total Header bytes = 54 [[DIM|DIM]] BMP [[AS|AS]] BMPFormat [[DIM|DIM]] x [[AS|AS]] [[LONG|LONG]], y [[AS|AS]] [[LONG|LONG]] [[DIM|DIM]] temp [[AS|AS]] [[STRING|STRING]] * 3 [[DIM|DIM]] m [[AS|AS]] [[_MEM|_MEM]], n [[AS|AS]] [[_MEM|_MEM]] [[DIM|DIM]] o [[AS|AS]] [[_OFFSET|_OFFSET]] m = [[_MEMIMAGE|_MEMIMAGE]](image&) 'get image information from memory handle [[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& = 4 OffsetBITS& = 54 'no palette in 24/32 bit BPP% = 24 NumColors& = 0 '24/32 bit say zero BMP.PWidth = (x2% - x1%) + 1 BMP.PDepth = (y2% - y1%) + 1 ImageSize& = BMP.PWidth * BMP.PDepth BMP.ID = "BM" BMP.Size = ImageSize& * 3 + 54 BMP.Blank = 0 BMP.Offset = 54 BMP.Hsize = 40 BMP.Planes = 1 BMP.BPP = 24 BMP.Compression = 0 BMP.ImageBytes = ImageSize& BMP.Xres = 3780 BMP.Yres = 3780 BMP.NumColors = 0 BMP.SigColors = 0 Compression& = 0 WidthPELS& = 3780 DepthPELS& = 3780 SigColors& = 0 f = [[FREEFILE|FREEFILE]] n = [[_MEMNEW|_MEMNEW]](BMP.Size) 'allocate memory for file data [[_MEMPUT|_MEMPUT]] n, n.OFFSET, BMP 'place bitmap header in memory o = n.OFFSET + 54 'offset after header for RGB color data ' 'run memory reads without error checking! [[$CHECKING|$CHECKING]]:OFF y = y2% + 1 w& = [[_WIDTH (function)|_WIDTH]](image&) DO y = y - 1: x = x1% - 1 DO x = x + 1 [[_MEMGET|_MEMGET]] m, m.OFFSET + (w& * y + x) * 4, temp 'read 3 color bytes [[_MEMPUT|_MEMPUT]] n, o, temp 'place into n memory after o offset o = o + 3 'increase offset 3 bytes per loop [[LOOP|LOOP]] [[UNTIL|UNTIL]] x = x2% [[LOOP|LOOP]] [[UNTIL|UNTIL]] y = y1% [[$CHECKING|$CHECKING]]:ON [[_MEMFREE|_MEMFREE]] m [[OPEN|OPEN]] Filename$ [[FOR...NEXT|FOR]] [[BINARY|BINARY]] [[AS|AS]] #f t$ = [[SPACE$|SPACE$]](BMP.Size) [[_MEMGET|_MEMGET]] n, n.OFFSET, t$ [[PUT|PUT]] #f, , t$ [[_MEMFREE|_MEMFREE]] n [[CLOSE|CLOSE]] #f [[END SUB|END SUB]] |
See also:
- SAVEIMAGE (QB64 Image to Bitmap SUB by Galleon)
- Program ScreenShots (Member program for legacy screen modes)
- ThirtyTwoBit SUB (QB64 Image area to bitmap)
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page