之前写一个gui,需要嵌入图片到ahk代码,但HEX太长,所以有了这么一个压缩脚本
zip(a){ ;自定义设置 size = 2 ;多少字节一取样 比如24为bmp 6字节 ;完毕 last = Loop { if a = { if times > 1 out = % out "[" times "_" last "]" Else out = % out last Break } StringLeft, tmp_var, a, %size% StringTrimLeft, a, a, %size% if tmp_var <> %last% { if last = { last := tmp_var times = 1 } Else { if times > 1 { out = % out "[" times "_" last "]" last := tmp_var times = 1 } Else { out = % out last last := tmp_var times = 1 } } } Else { times += 1 } } return %out% } unzip(a){ StringSplit, var, a, ] Loop % var0-1 { tmp_var = % var%A_Index% StringSplit, key, tmp_var, [ StringSplit, xx, key2, _ unzip_var = Loop % xx1 { unzip_var = % unzip_var xx2 } out = % out key1 unzip_var } out := out var%var0% Return out } file2hex(file){ tmp_file := FileOpen(file, "r") while not tmp_file.AtEOF { tmp_file.RawRead(Data, 1) SetFormat, IntegerFast, hex tmp_hex := asc(Data) StringReplace, tmp_hex, tmp_hex, 0x, , All SetFormat, IntegerFast, d if StrLen(tmp_hex) = 1 tmp_hex = 0%tmp_hex% hex = % hex tmp_hex } tmp_file.Close() Return hex } hex2file(hex,file){ tmp_file := FileOpen(file, "w") StringLen, len, hex loop % len/2 { if blob = break StringLeft, tmp_hex, blob, 2 StringTrimLeft, blob, blob, 2 tmp_hex := "0x" tmp_hex tmp_file.WriteUChar(tmp_hex) } tmp_file.Close() tmp_file = } a := file2hex("D:\Desktop\no.bmp") zip := zip(a) FileAppend, %zip%, zip.txt b := unzip(zip) hex2file(b,"out.txt")
60 queries in 2.445 seconds |