在这有:http://www.autoitx.com/thread-20741-1-1.htmlFunc _myWriteArrayToBmpFile($func_array, $s_newFile)
If UBound($func_array)=0 Or UBound($func_array,3)>0 Then Return ""
;If UBound($func_array,2)>0 Then _myArray2dTo1d($func_array)
If StringLower(StringRight($s_newFile,4))<>".bmp" Then $s_newFile &=".Bmp";只支持Bmp
FileDelete($s_newFile)
If FileExists($s_newFile) Then Return "";不可写'
If UBound($func_array,2)=0 Then;一维数组
Local $i_height = UBound($func_array) ;高
Local $i_width = StringLen($func_array[0])/6 ;宽
Else;二维数组
Local $i_height = UBound($func_array,2) ;高
Local $i_width = UBound($func_array);宽
EndIf
Local $head=DllStructcreate("ubyte[54]")
;lets create a bitmapfile with the given data
Local $Bmpheader = DllStructCreate("align 1;char BM[2];uint Size;uint res;uint Offset;uint BMHI;uint Width;uint Height;short Planes;"& _
"short BPP;uint BIcomp;int SizeImg;uint reshor;uint resver;uint col;uint colused", dllstructgetptr($head))
;fill struct(bitmapheader) with data
Local $iLen=$i_width*$i_height*3
DllStructSetData($bmpheader,"BM","BM")
DllStructSetData($bmpheader,"Size",54+$iLen)
DllStructSetData($bmpheader,"Offset",54)
DllStructSetData($bmpheader,"BMHI",40)
DllStructSetData($bmpheader,"Width",$i_width)
DllStructSetData($bmpheader,"Height",-$i_height)
DllStructSetData($bmpheader,"Planes",1)
DllStructSetData($bmpheader,"BPP",24)
DllStructSetData($bmpheader,"BIcomp",0)
Local $header = dllstructgetdata($head,1) ;headerdata
Local $filehandle = FileOpen($s_newFile, 18) ;write file
FileWrite($filehandle,$header)
Local $s_bott="",$i
For $i = 1 To Mod($i_width,4)
$s_bott &= "0"
Next
;ConsoleWrite($s_bott&@CRLF)
Local $y
If UBound($func_array,2)=0 Then
For $y=0 To $i_height-1
FileWrite($filehandle,"0x"&$func_array[$y])
FileWrite($filehandle,$s_bott)
Next
Else
Local $x
For $y=0 To $i_height-1
For $x=0 To $i_width-1
FileWrite($filehandle,"0x"&$func_array[$x][$y])
Next
FileWrite($filehandle,$s_bott)
Next
EndIf
FileClose($filehandle)
If FileExists($s_newFile) Then
Return $s_newFile
Else
Return ""
EndIf
EndFunc
|