This subroutine works perfectly:
http://www.qb64.org/wiki/SAVEIMAGE
but I have to say that I don't have understood anything at all how it works, also reading the explanation.
Starting from:
b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
It a mystery. Someone has an idea?
BMP files are actually rather simple to create and decode. The way they work is to basically store your image in 2 parts — the header and then the data.
The header is a leading batch of information that basically stores your height, width, color size, and such, and it looks like:
TYPE BMPEntry ' Description Bytes QB64 Function
ID AS STRING * 2 ' File ID("BM" text or 19778 AS Integer) 2 CVI("BM")
Size AS LONG ' Total Size of the file 4 LOF
Res1 AS INTEGER ' Reserved 1 always 0 2
Res2 AS INTEGER ' Reserved 2 always 0 2
Offset AS LONG ' Start offset of image pixel data 4 (add one for GET)
END TYPE ' Total 14
TYPE BMPHeader 'BMP header also used in Icon and Cursor files(.ICO and .CUR)
Hsize AS LONG ' Info header size (always 40) 4
PWidth AS LONG ' Image width 4 _WIDTH(handle&)
PDepth AS LONG ' Image height (doubled in icons) 4 _HEIGHT(handle&)
Planes AS INTEGER ' Number of planes (normally 1) 2
BPP AS INTEGER ' Bits per pixel(palette 1, 4, 8, 24) 2 _PIXELSIZE(handle&)
Compression AS LONG ' Compression type(normally 0) 4
ImageBytes AS LONG ' (Width + padder) * Height 4
Xres AS LONG ' Width in PELS per metre(normally 0) 4
Yres AS LONG ' Depth in PELS per metre(normally 0) 4
NumColors AS LONG ' Number of Colors(normally 0) 4 2 ^ BPP
SigColors AS LONG ' Significant Colors(normally 0) 4
END TYPE ' Total Header bytes = 40
After the header, unless you’re storing a color palette, or using RLE compression, comes the data, which is basically the color value of each pixel which encompasses an image.