Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- saveBMP(2,2,{255,0,0,0,255,0,0,0,255,255,255,255})
- function saveBMP(filename, width, height, pixels)
- size_1, size_2, size_3, size_4 = convert(height*width*3, 4)
- width_1, width_2, width_3, width_4 = convert(width, 4)
- height_1, height_2, height_3, height_4 = convert(height, 4)
- sizeArrayColors = 4 * width * height
- size_array_1, size_array_2, size_array_3, size_array_4 = convert(sizeArrayColors, 4)
- local byteArray =
- {
- --bmp header
- 0x42, 0x4D, -- magic numbers
- size_1, size_2, size_3, size_4, --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
- width_1, width_2, width_3, width_4, -- largura
- height_1, height_2, height_3, height_4, -- altura
- 0x01, 0x00,
- 0x18, 0x00, -- numero de bits por pixel (24bits/pixel)
- 0x00, 0x00, 0x00, 0x00,
- size_array_1, size_array_2, size_array_3, size_array_4, -- numeros de bytes no array de cores
- 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/(width*3)) % 1 == 0)then
- for i=1, width do
- file:write(0x00)
- end
- end
- end
- file:close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement