Advertisement
dalvorsn

Untitled

May 14th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. function saveBMP(filename, pixels)
  2.  
  3.     local byteArray =
  4.     {
  5.     --bmp header
  6.     0x42, 0x4D, -- magic numbers
  7.     0x46, 0x00, 0x00, 0x00, --0x00, 0x12, 0x00, 0x00, -- tamanho em bytes da imagem (3072)
  8.     0x00, 0x00, 0x00, 0x00, -- sem uso
  9.     0x36, 0x00, 0x00, 0x00, -- endereço de onde começam as cores
  10.     --dib header
  11.     0x28, 0x00, 0x00, 0x00, -- tamanho do dib header em bytes - 40
  12.     0x02, 0x00, 0x00, 0x00, -- altura - 32
  13.     0x02, 0x00, 0x00, 0x00, -- largura - 32
  14.     0x01, 0x00,
  15.     0x18, 0x00,    -- numero de bits por pixel (24bits/pixel)
  16.     0x00, 0x00, 0x00, 0x00,
  17.     0x10, 0x00, 0x00, 0x00,-- 0x36, 0x0B, 0x00, 0x00, --numeros de bytes no array de cores  -> (3126 - 54) -: 3072  
  18.     0x13, 0x0B, 0x00, 0x00, -- resolução horizontal bit/meter
  19.     0x13, 0x0B, 0x00, 0x00, -- resolução horizontal bit/meter
  20.     0x00, 0x00, 0x00, 0x00,
  21.     0x00, 0x00, 0x00, 0x00
  22.     }
  23.     file = io.open(filename..".bmp", "w+b")
  24.     for _, byte in pairs(byteArray) do
  25.         file:write(type(byte) == "number" and string.char(byte) or byte)
  26.     end
  27.     for index, byte in pairs(pixels) do
  28.         file:write(type(byte) == "number" and string.char(byte) or byte)
  29.         if(index/6 % 1 == 0)then
  30.             file:write(0x00,0x00)
  31.         end
  32.     end
  33.     file:close()
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement