Foreword:
After Goyyah showed its possible to write a dynamic bitmap file using Laszlo's and PhiLho's Binary Read and Write Functions, i wondered if it would be possible to simply include a bitmap in hexadecimal form inside your script, write it, then display it. Heres what i got:
Application:
I took a 24 by 24 Bitmap and turned it into Hexadecimal by saving it and reading it with Laszlos BinReadIt doubles the file size excactly because each byte in the .bmp (for example "0a") is represented by two ascii bytes, since each char takes one byte.The BMP file was 2,784 bytes
in text file takes 5,568 bytes
But then you exctract the bitmap, thus making the data again so we can conclude:but decreases cluttered and makes it possible to send files with your script.including bitmaps in your script triples the space they take up
Example:
The following script creates this gui
using no external files!(except that one that it writes of course)#singleinstance force #noenv gosub, definepicture WriteFile("logo.bmp",picture) gui, add, pic,x100,logo.bmp gui, add, text,xm,The Image above was created by the script. gui, show,, by Veovis return WriteFile(file,data) { Handle := DllCall("CreateFile","str",file,"Uint",0x40000000 ,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0) Loop { if strlen(data) = 0 break StringLeft, Hex, data, 2 StringTrimLeft, data, data, 2 Hex = 0x%Hex% DllCall("WriteFile","UInt", Handle,"UChar *", Hex ,"UInt",1,"UInt *",UnusedVariable,"UInt",0) } DllCall("CloseHandle", "Uint", Handle) return } definepicture: picture = ( join 424d000000000000000036000000280000001800000018000000010018000000000000000000000000000000000000000000 00000000c9c7c77d99776eae646baa6068a75d64a45961a1565d9d525a9a4f57974b5394475091444d8d404a8a3d46873943 84363f81323c7e2e397b2b3677275f7d57c8c6c5e3dfe0e3dfe077af6f74b46b71b1686eae646baa6068a75d64a45961a156 5d9d525a9a4f57974b5394475091444d8d404a8a3d4687394384363f81323c7e2e397a2a3677273b742ec8c6c5e3dfe07aba 7277b76e74b46b71b1686ead6468a55d629e585f9c55609f555d9d525a9a4f56974b5394475091444d8c4048863b42803641 7f343f80323c7e2e397a2a3677275f7d57e3dfe07ebd767aba7277b76e74b46b6dab655e95554f7e475182495c975260a055 5d9d525a9a4f56974b5394474d8c4242793738682e396e2e3f7d333f81323c7e2e397a2a367727e3dfe081c0797ebd757aba 7277b76e73a96ba6bca3758a713c603655884c619f5761a1565d9d525a9a4f56974b578e4c9bb1974f694a2d54253d773243 84363f81323c7e2e397a2ae3dfe085c37d81c0797ebd757aba72d0e1ceffffffffffff5a725651814964a05964a45961a156 5d9d525a9a4fc7d9c4fffffff1f3f12849213e74334687394384363f81323c7e2ee3dfe088c68085c37d81c0797ebd75dae7 d8ffffffffffff677e6453834c67a35c68a75d64a45961a1565d9d52d3e1d0ffffffffffff294a224176364a8a3d46873943 84363f8132e3dfe08bc98388c68085c37d81c079dce9daffffffffffff687f6556864f6aa6606baa6068a75d64a45961a156 d3e1d1ffffffffffff2b4c244379384d8d40498a3c468739438436e3dfe08ecd878bc98388c68085c37dddebdbffffffffff ff677c644d78475f9558639b5a639d58629f58619f57d4e2d2ffffffffffff2c4e27467c3c5090434d8d40498a3c468739e3 dfe091d08b8ecd878bc98388c680c5dec2ffffffffffff62756038563442673d4870424b77454f7e47518449d2ddd0ffffff ffffff2e4f29487f3f5394475090434d8d40498a3ce3dfe095d38e91d08b8ecd878bc983bedbbaffffffffffffffffffcbd1 cab1bab097a49564796159715534532fccd3caffffffffffff30512a4c814256974b5394475090434d8d40e3dfe098d69295 d38e91d08a8ecd87bfdcbcffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff31512b 4d82445a994f56974b539447509043e3dfe09cda9698d69295d38e91d08ac1debeffffffffffffdadfdaffffffffffffffff ffffffffffffffffffffffffffffffffffffff31502c4d80445b9a505a9a4f56974b539447e3dfe09fdd999bd99598d69295 d38ec2dfbfffffffffffff6f856d64945e8cc085a4ce9ebad8b5c9dfc6dae8d8f5f8f4ffffffffffff4b66474d7e445d9a52 5d9d525a9a4e56974be3dfe0a2e09d9fdd999bd99598d692c4e1c1ffffffffffff70866e6796617fbb7781c0797dbd757aba 7177b76ed8e6d6ffffffffffff657b614e7e46609e5660a0555d9d52599a4ee3dfe0a5e3a1a2e09d9fdd999bd995c5e2c3ff ffffffffff72886f69986383be7b84c37c81c0797dbd757aba71dae8d8ffffffffffff667c6351814963a05864a45960a055 5d9d52e3dfe0a8e6a4a5e3a1a2e09d9fdd99c7e3c4ffffffffffff7389706b9b6686c17e88c68084c37c81c0797dbd75dbe9 d9ffffffffffff677d6352804a66a25b67a75c64a45960a055e3dfe0aceaa8a8e6a4a5e3a1a2e09dc9e6c7ffffffffffff75 8c736fa06a89c6828bc98388c68084c37c81c079cbe1c8ffffffffffff677d6452804a68a35e6baa6067a75c64a459e3dfe0 afedabaceaa8a8e6a4a5e3a0cdeacaffffffffffff85a1827cb1778ecc878ecc868bc98388c68084c37cb7d9b2ffffffffff ff96ab935b8d546ca8636ead646baa6067a65ce3dfe0b2f0aeafedababe9a7a8e6a4c0eabcfffffff7faf692c08e8fc98993 d28d91d08a8ecc868bc98388c6808bc684f6faf6ffffff95ba906ea96573b26a71b0676dad636aaa60e3dfe0b6f3b2b2f0ae afedababe9a7a8e6a4b4e6b0abe0a69cd9969ad89498d69294d38e91d08a8ecc868bc98388c68093ca8c97c9907bb97379b9 7077b76e73b36a70b0676dad63e3dfe0b9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294 d38e91d08a8ecc868bc98387c67f84c37c81c0797dbd757aba7176b66d73b36a7c9977e3dfe0b3e8b0b9f6b5b6f3b2b2f0ae afedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c37c81bf797dbc757ab9 7176ae6ec9c6c6e3dfe0cac7c7a0bc9db9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294 d38e91d08a8ecc868bc98387c67f84c27c81bf79819f7dc9c6c6e3dfe0e3dfe052804a68a35e6baa6067a75c64a459e3dfe0 e3dfe0e3dfe0ff657b614e7e46609e5660a0555d9d52599a4ee3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc49fdd999b d995c5e2c3ffffffffffff72886f69986383be7b84c37c81c0797dbd757aba71dae8d8ffffffffffff667c6351814963a058 64a45960a0555d9d52e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4a2e09d9fdd99c7e3c4ffffffffffff7389706b9b 6686c17e88c68084c37c81c0797dbd75dbe9d9ffffffffffff677d6352804a66a25b67a75c64a45960a055e3dfe0e3dfe0e3 dfe0e3dfe0e3dfe0e3dfe0d1cbc4a5e3a1a2e09dc9e6c7ffffffffffff758c736fa06a89c6828bc98388c68084c37c81c079 cbe1c8ffffffffffff677d6452804a68a35e6baa6067a75c64a459e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4a8e6 a4a5e3a0cdeacaffffffffffff85a1827cb1778ecc878ecc868bc98388c68084c37cb7d9b2ffffffffffff96ab935b8d546c a8636ead646baa6067a65ce3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4abe9a7a8e6a4c0eabcfffffff7faf692c08e 8fc98993d28d91d08a8ecc868bc98388c6808bc684f6faf6ffffff95ba906ea96573b26a71b0676dad636aaa60e3dfe0e3df e0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4afedababe9a7a8e6a4b4e6b0abe0a69cd9969ad89498d69294d38e91d08a8ecc868b c98388c68093ca8c97c9907bb97379b97077b76e73b36a70b0676dad63e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4 b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c37c81c0797dbd 757aba7176b66d73b36a7c9977e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4b6f3b2b2f0aeafedababe9a7a8e6a4a5 e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c37c81bf797dbc757ab97176ae6ec9c6c6e3dfe0 e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4b9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d6 9294d38e91d08a8ecc868bc98387c67f84c27c81bf79819f7dc9c6c6e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1 cbc4cbc4b9f6b5b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387 c67f84c37c81bf797dbc757ab97176ae6ec9c6c6e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4d1cbc4a0bc9db9f6b5 b6f3b2b2f0aeafedababe9a7a8e6a4a5e3a0a2e09c9fdd999bd99598d69294d38e91d08a8ecc868bc98387c67f84c27c81bf 79819f7dc9c6c6e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0e3dfe0d1cbc4d1cbc4 ) return guiclose: exitapp
An an easy way to retrieve the data from a bmp file:
gui, add, edit, w400 vFile, gui, add, button, w100 gOpen x+10,Open File gui, add, edit, r40 w510 vOutput xm gui, show Open: gui, submit, nohide BinRead(file,data) Bin2Hex(h,data,res) guicontrol,,output,%h% return Bin2Hex(ByRef h, ByRef b, n=0) ; n bytes binary data -> stream of 2-digit hex { ; n = 0: all (SetCapacity can be larger than used!) format = %A_FormatInteger% ; save original integer format SetFormat Integer, Hex ; for converting bytes to hex m := VarSetCapacity(b) If (n < 1 or n > m) n := m Address := &b h = Loop %n% { x := *Address ; get byte in hex StringTrimLeft x, x, 2 ; remove 0x x = 0%x% ; pad left StringRight x, x, 2 ; 2 hex digits h = %h%%x% Address++ } SetFormat Integer, %format% ; restore original format } BinRead(file, ByRef data, n=0, offset=0) { h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0) IfEqual h,-1, SetEnv, ErrorLevel, -1 IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file m = 0 ; seek to offset IfLess offset,0, SetEnv,m,2 r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m) IfEqual r,0, SetEnv, ErrorLevel, -3 IfNotEqual ErrorLevel,0, { t = %ErrorLevel% ; save ErrorLevel to be returned DllCall("CloseHandle", "Uint", h) ErrorLevel = %t% ; return seek error Return 0 } m := DllCall("GetFileSize","UInt",h,"Int64 *",r) If (n < 1 or n > m) n := m Granted := VarSetCapacity(data, n, 0) IfLess Granted,%n%, { ErrorLevel = Mem=%Granted% Return 0 } result := DllCall("ReadFile","UInt",h,"Str",data,"UInt",n,"UInt *",Read,"UInt",0) if (!result or Read < n) t = -3 IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel% h := DllCall("CloseHandle", "Uint", h) IfEqual h,-1, SetEnv, ErrorLevel, -2 IfNotEqual t,,SetEnv, ErrorLevel, %t%-%ErrorLevel% Return Read }
I hope you all enjoy, and please give me feedback!
One thing im curious of is if its possible to compress the raw hex data of the picture.