Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function saveBMP(filename, pixels)
- local byteArray =
- {
- --bmp header
- 0x42, 0x4D, -- magic numbers
- 0x46, 0x00, 0x00, 0x00, --0x00, 0x12, 0x00, 0x00, -- tamanho em bytes da imagem (3072)
- 0x00, 0x00, 0x00, 0x00, -- sem uso
- 0x36, 0x00, 0x00, 0x00, -- endereço de onde começam as cores
- --dib header
- 0x28, 0x00, 0x00, 0x00, -- tamanho do dib header em bytes - 40
- 0x02, 0x00, 0x00, 0x00, -- altura - 32
- 0x02, 0x00, 0x00, 0x00, -- largura - 32
- 0x01, 0x00,
- 0x18, 0x00, -- numero de bits por pixel (24bits/pixel)
- 0x00, 0x00, 0x00, 0x00,
- 0x10, 0x00, 0x00, 0x00,-- 0x36, 0x0B, 0x00, 0x00, --numeros de bytes no array de cores -> (3126 - 54) -: 3072
- 0x13, 0x0B, 0x00, 0x00, -- resolução horizontal bit/meter
- 0x13, 0x0B, 0x00, 0x00, -- resolução horizontal bit/meter
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
- }
- file = io.open(filename..".bmp", "w+b")
- for _, byte in pairs(byteArray) do
- file:write(type(byte) == "number" and string.char(byte) or byte)
- end
- for index, byte in pairs(pixels) do
- file:write(type(byte) == "number" and string.char(byte) or byte)
- if(index/6 % 1 == 0)then
- file:write(0x00,0x00)
- end
- end
- file:close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement