有没有au3生成动态gif的?
不知道有没有用au3来把多个hBitmap图片合成一个动态的gif现在我都只能调用外来的DLL来做,有没有纯au3可以干这件事的? 能有DLL来做就是高人了,纯au3估计没有这方面的函数吧 官网有一个,不过不是直接生成的,是将图片转为gif图片后,然后合并,你可以搜索一下 官网有一个,不过不是直接生成的,是将图片转为gif图片后,然后合并,你可以搜索一下
gto250 发表于 2011-9-9 19:22 http://www.autoitx.com/images/common/back.gif
没有搜到呀
关键就是如何:合并?
能不能给个地址 #Include <WinAPI.au3>
Dim $OptionsArray
For $i = 1 To 2
$OptionsArray = AddFile($OptionsArray,@ScriptDir & "\fistcash\fistcash0" & $i & ".gif",10)
Next
MakeGIF("fistcash.gif",$OptionsArray)
Func AddFile($OptionsArray,$sFile,$iDelayTime = 1,$LOOP = True)
if Not IsArray($OptionsArray) Then
Local $XOptionsArray
$OptionsArray = $XOptionsArray
Else
ReDim $OptionsArray
EndIf
$OptionsArray = $sFile
$OptionsArray = $iDelayTime
$OptionsArray = $LOOP
Return $OptionsArray
EndFunc
Func MakeGIF($FileOut,$OptionsArray)
Local $iGctSize=
Local $LOOP = $OptionsArray , $nBytes
$hFileOut =_WinAPI_CreateFile($FileOut,1)
$TegGIF_HEADER = _
"char cSignature;" & _
"char cVersion"
$GIF_HEADER = DllStructCreate($TegGIF_HEADER)
DllStructSetData($GIF_HEADER,1,"GIF")
DllStructSetData($GIF_HEADER,2,"89a")
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($GIF_HEADER),DllStructGetSize($GIF_HEADER), $nBytes)
$GIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructCreate("BYTE")
$PGIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructGetPtr($GIF_LOGICAL_SCREEN_DESCRIPTOR)
_WinAPI_WriteFile($hFileOut,$PGIF_LOGICAL_SCREEN_DESCRIPTOR,7, $nBytes)
if ($LOOP) Then
$Struct = DllStructCreate("BYTE[" & StringLen("0x21FF0B4E45545343415045322E300301FFFF00") & "]")
;"\41\377\013NETSCAPE2.0\003\001\377\377\0" ==> 0x21FF0B4E45545343415045322E300301FFFF00
DllStructSetData($Struct,1,"0x21FF0B4E45545343415045322E300301FFFF00")
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($Struct),19, $nBytes)
EndIf
For $i = 0 To UBound($OptionsArray) - 1
$sFile = $OptionsArray[$i]
$iDelayTime = $OptionsArray[$i]
$hFileIn =_WinAPI_CreateFile($sFile,2,2)
if Not ($hFileIn) Then _
Return MsgBox(0,"MSG","Could not open file. GIF creation aborted.")
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($GIF_HEADER),DllStructGetSize($GIF_HEADER), $nBytes)
$cSignature = DllStructGetData($GIF_HEADER,1)
$cVersion = DllStructGetData($GIF_HEADER,2)
$BOOL = ($cVersion == "89a") Or ($cVersion == "87a")
if Not ($cSignature == "GIF") Or Not ($BOOL) Then
MsgBox(0,"MSG","Not a GIF file, or incorrect version number.")
_WinAPI_CloseHandle($hFileIn)
_WinAPI_CloseHandle($hFileOut)
Return
EndIf
$szColorTable = DllStructCreate("char")
$LGIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructCreate("BYTE")
$PLGIF_LOGICAL_SCREEN_DESCRIPTOR = DllStructGetPtr($LGIF_LOGICAL_SCREEN_DESCRIPTOR)
_WinAPI_ReadFile($hFileIn,$PLGIF_LOGICAL_SCREEN_DESCRIPTOR,7, $nBytes)
$OutPtr = $PLGIF_LOGICAL_SCREEN_DESCRIPTOR + 4
$Structivalue = DllStructCreate("BYTE",$OutPtr)
$value = DllStructGetData($Structivalue,1)
$iGctFlag = int(BitAND(int(0x01) , $value))
$iSizeOfGct = BitAND(int(0xF) , $value)
if ($iGctFlag) Then
_WinAPI_ReadFile($hFileIn, DllStructGetPtr($szColorTable),$iGctSize[$iSizeOfGct], $nBytes)
EndIf
$Structivalue1 = DllStructCreate("USHORT",$PGIF_LOGICAL_SCREEN_DESCRIPTOR)
$OutPtr1 = DllStructGetPtr($Structivalue1)
$AiWidth = DllStructGetData($Structivalue1,1)
$Structivalue2 = DllStructCreate("USHORT",$PLGIF_LOGICAL_SCREEN_DESCRIPTOR)
$OutPtr2 = DllStructGetPtr($Structivalue2)
$BiWidth = DllStructGetData($Structivalue2,1)
$OutPtr3 = $PGIF_LOGICAL_SCREEN_DESCRIPTOR + 2 ; 2 Size Of USHORT
$Structivalue3 = DllStructCreate("USHORT",$OutPtr3)
$AiHeight = DllStructGetData($Structivalue3,1)
$OutPtr4 = $PLGIF_LOGICAL_SCREEN_DESCRIPTOR + 2 ; 2 Size Of USHORT
$Structivalue4 = DllStructCreate("USHORT",$OutPtr4)
$BiHeight = DllStructGetData($Structivalue4,1)
if ($AiWidth < $BiWidth ) Then
RtlMoveMemory($OutPtr1,$OutPtr2,2)
EndIf
if ($AiHeight < $BiHeight) Then
RtlMoveMemory($OutPtr3,$OutPtr4,2)
EndIf
$C = DllStructCreate("BYTE")
While 1
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes,0)
if ($nBytes == 0) Then
MsgBox(0,"MSG","Premature end of file encountered; no GIF image data present.")
_WinAPI_CloseHandle($hFileIn)
_WinAPI_CloseHandle($hFileOut)
return
EndIf
$IC = DllStructGetData($C,1)
if ($IC == 0x2C) Then
$GIF_IMAGE_DESCRIPTOR = DllStructCreate("BYTE")
$PGIF_IMAGE_DESCRIPTOR = DllStructGetPtr($GIF_IMAGE_DESCRIPTOR)
_WinAPI_ReadFile($hFileIn,$PGIF_IMAGE_DESCRIPTOR,9,$nBytes)
$OutPtr5 = $PGIF_IMAGE_DESCRIPTOR + 8 ;Sizeof USHORT * 4
$Structivalue5 = DllStructCreate("BYTE",$OutPtr5)
$value = DllStructGetData($Structivalue5,1)
$iLctFlag = int(BitAND(int(0x01) , $value))
$iSizeOfLct = int(BitAND(int(0xF) , $value))
if ($iLctFlag) Then
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($szColorTable),$iGctSize[$iSizeOfLct],$nBytes)
Else
$Structivalue5 = DllStructCreate("BYTE")
DllStructSetData($Structivalue5,1,0x87)
$outPtr6 = $PGIF_IMAGE_DESCRIPTOR + 8 ;Sizeof USHORT * 4
$OutPtr7 = DllStructGetPtr($Structivalue5)
RtlMoveMemory($OutPtr6,$OutPtr7,1)
$iSizeOfLct = int(BitAND(int(0xF) , 0x87))
EndIf
ExitLoop
ElseIf ($IC == 0x21) Then
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
$IC = DllStructGetData($C,1)
if ($IC == 0xF9) Then
$GIF_GRAPHIC_CONTROL_EXTENSION = DllStructCreate("BYTE")
$PGIF_GRAPHIC_CONTROL_EXTENSION = DllStructGetPtr($GIF_GRAPHIC_CONTROL_EXTENSION)
_WinAPI_ReadFile($hFileIn,$PGIF_GRAPHIC_CONTROL_EXTENSION,6,$nBytes)
Else
While 1
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
$IC = DllStructGetData($C,1)
if Not ($IC) Then ExitLoop
_WinAPI_SetFilePointer($hFileIn,$IC,1)
WEnd
EndIf
EndIf
WEnd
$Structivalue5 = DllStructCreate("BYTE")
DllStructSetData($Structivalue5,1,4)
$valuePtr1 = DllStructGetPtr($Structivalue5)
RtlMoveMemory($PGIF_GRAPHIC_CONTROL_EXTENSION,$valuePtr1,1)
$Structivalue6 = DllStructCreate("USHORT")
DllStructSetData($Structivalue6,1,$iDelayTime)
$valuePtr2 = DllStructGetPtr($Structivalue6)
$OutPtr8 = $PGIF_GRAPHIC_CONTROL_EXTENSION + 2 ; 2 size Of BYTE * 2
RtlMoveMemory($OutPtr8,$valuePtr2,2)
$Structivalue7 = DllStructCreate("BYTE")
DllStructSetData($Structivalue7,1,9)
$valuePtr3 = DllStructGetPtr($Structivalue7)
$OutPtr9 = $PGIF_GRAPHIC_CONTROL_EXTENSION + 1 ; 1 size Of BYTE
RtlMoveMemory($OutPtr9,$valuePtr3,1)
$C = DllStructCreate("char")
DllStructSetData($C,1,Chr(0x21))
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
DllStructSetData($C,1,Chr(0xF9))
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
_WinAPI_WriteFile($hFileOut,$PGIF_GRAPHIC_CONTROL_EXTENSION,6, $nBytes)
DllStructSetData($C,1,Chr(0x2C))
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
_WinAPI_WriteFile($hFileOut,$PGIF_IMAGE_DESCRIPTOR,9, $nBytes)
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($szColorTable),$iGctSize[$iSizeOfLct], $nBytes)
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
$C = DllStructCreate("BYTE")
While 1
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($C),1,$nBytes)
_WinAPI_WriteFile($hFileOut, DllStructGetPtr($C),1, $nBytes)
$IC = DllStructGetData($C,1)
if Not ($IC) Then ExitLoop
_WinAPI_ReadFile($hFileIn,DllStructGetPtr($szColorTable),$IC,$nBytes)
_WinAPI_WriteFile($hFileOut,DllStructGetPtr($szColorTable),$IC,$nBytes)
WEnd
_WinAPI_CloseHandle($hFileIn)
Next
$C = DllStructCreate("char")
DllStructSetData($C,1,Chr(0x3B))
_WinAPI_WriteFile($hFileOut,DllStructGetPtr($C),1,$nBytes)
_WinAPI_SetFilePointer($hFileOut,6,0)
_WinAPI_WriteFile($hFileOut,$PGIF_LOGICAL_SCREEN_DESCRIPTOR,7, $nBytes)
_WinAPI_CloseHandle($hFileOut)
EndFunc
Func RtlMoveMemory($sourcePtr,$destPtr,$Size)
DllCall("Kernel32.dll","none","RtlMoveMemory","ptr",$sourcePtr,"ptr",$destPtr,"dword",$Size)
EndFunc 谢谢
好东西
看起来gif内部文件结构还是有点复杂的 谢谢分享... 本帖最后由 happytc 于 2011-9-10 22:36 编辑
回复 5# gto250
找个这个东西的原发地了
我把它发在这里,以给需要者,也算是多个资料
http://www.whitsoftdev.com/unfreez/
不过上面的是用C++写的。
一个家伙把它改成了au3的了。就象P版经常干的活一样。
unfreez
http://www.whitsoftdev.com/unfreez/
typedef struct {
char cSignature; // Must be 'GIF'
char cVersion; // Must be '89a'
} GIF_HEADER;
typedef struct { // 7 bytes
unsigned short iWidth;
unsigned short iHeight;
unsigned char iSizeOfGct : 3;
unsigned char iSortFlag : 1;
unsigned char iColorResolution : 3;
unsigned char iGctFlag : 1;
unsigned char iBackgroundColorIndex;
unsigned char iPixelAspectRatio;
} GIF_LOGICAL_SCREEN_DESCRIPTOR;
typedef struct { // 6 bytes
unsigned char iBlockSize; // Must be 4
unsigned char iTransparentColorFlag : 1;
unsigned char iUserInputFlag : 1;
unsigned char iDisposalMethod : 3;
unsigned char iReserved : 3;
unsigned short iDelayTime;
unsigned char iTransparentColorIndex;
unsigned char iBlockTerminator; // Must be 0
} GIF_GRAPHIC_CONTROL_EXTENSION;
typedef struct { // 9 bytes
unsigned short iLeft;
unsigned short iTop;
unsigned short iWidth;
unsigned short iHeight;
unsigned char iSizeOfLct : 3;
unsigned char iReserved : 2;
unsigned char iSortFlag : 1;
unsigned char iInterlaceFlag : 1;
unsigned char iLctFlag : 1;
} GIF_IMAGE_DESCRIPTOR;
#pragma pack(pop,gifpacking)
unsigned short iGctSize[]={6,12,24,48,96,192,384,768};
void MakeGIF()
{
OPENFILENAME ofn;
char szFileName;
DWORD dwIndex, dw;
char szColorTable;
unsigned char c;
HANDLE hFileOut, hFileIn;
GIF_HEADER gh;
GIF_LOGICAL_SCREEN_DESCRIPTOR glsd1, glsd;
GIF_GRAPHIC_CONTROL_EXTENSION ggce;
GIF_IMAGE_DESCRIPTOR gid;
ZeroMemory(&glsd1,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR));
szFileName=0;
ofn.lStructSize=sizeof(ofn);
ofn.hwndOwner=hMainDlg;
ofn.hInstance=hInst;
ofn.lpstrFilter="GIF Files (*.gif)\0*.gif\0";
ofn.lpstrCustomFilter=NULL;
ofn.nMaxCustFilter=0;
ofn.nFilterIndex=1;
ofn.lpstrFile=szFileName;
ofn.nMaxFile=MAX_PATH;
ofn.lpstrFileTitle=NULL;
ofn.nMaxFileTitle=0;
ofn.lpstrInitialDir=NULL;
ofn.lpstrTitle="Make Animated GIF";
ofn.Flags=OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
ofn.nFileOffset=NULL;
ofn.nFileExtension=NULL;
ofn.lpstrDefExt="gif";
ofn.lCustData=NULL;
ofn.lpfnHook=NULL;
ofn.lpTemplateName=NULL;
if (GetSaveFileName(&ofn)) {
hFileOut=CreateFile(szFileName,GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,0,0);
strncpy((char *)&gh,"GIF89a",6);
WriteFile(hFileOut,&gh,sizeof(GIF_HEADER),&dw,0);
WriteFile(hFileOut,&glsd1,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR),&dw,0);
if (IsDlgButtonChecked(hMainDlg,IDC_CHECK_MAIN_LOOP)) {
WriteFile(hFileOut,"\41\377\013NETSCAPE2.0\003\001\377\377\0",19,&dw,0);
}
for (dwIndex=0;dwIndex<(unsigned)SendDlgItemMessage(hMainDlg,IDC_LIST_MAIN_FRAMES,LB_GETCOUNT,0,0);dwIndex++) {
ZeroMemory(&glsd,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR));
ZeroMemory(&ggce,sizeof(GIF_GRAPHIC_CONTROL_EXTENSION));
ZeroMemory(&gid,sizeof(GIF_IMAGE_DESCRIPTOR));
hFileIn=CreateFile((char *)SendDlgItemMessage(hMainDlg,IDC_LIST_MAIN_FRAMES,LB_GETITEMDATA,dwIndex,0),GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
if (hFileIn==INVALID_HANDLE_VALUE) {
MessageBox(hMainDlg,"Could not open file. GIF creation aborted.",0,0);
CloseHandle(hFileOut);
return;
}
ReadFile(hFileIn,&gh,sizeof(GIF_HEADER),&dw,0);
if (strncmp(gh.cSignature,"GIF",3) || (strncmp(gh.cVersion,"89a",3) && strncmp(gh.cVersion,"87a",3))) {
MessageBox(hMainDlg,"Not a GIF file, or incorrect version number.",0,MB_ICONEXCLAMATION);
CloseHandle(hFileIn);
CloseHandle(hFileOut);
return;
}
ReadFile(hFileIn,&glsd,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR),&dw,0);
if (glsd.iGctFlag) ReadFile(hFileIn,szColorTable,iGctSize,&dw,0);
if (glsd1.iWidth<glsd.iWidth) glsd1.iWidth=glsd.iWidth;
if (glsd1.iHeight<glsd.iHeight) glsd1.iHeight=glsd.iHeight;
for (;;) {
ReadFile(hFileIn,&c,1,&dw,0);
if (dw==0) {
MessageBox(hMainDlg,"Premature end of file encountered; no GIF image data present.",0,MB_ICONEXCLAMATION);
CloseHandle(hFileIn);
CloseHandle(hFileOut);
return;
}
if (c==0x2C) {
ReadFile(hFileIn,&gid,sizeof(GIF_IMAGE_DESCRIPTOR),&dw,0);
if (gid.iLctFlag) {
ReadFile(hFileIn,szColorTable,iGctSize,&dw,0);
} else {
gid.iLctFlag=1;
gid.iSizeOfLct=glsd.iSizeOfGct;
}
break;
} else if (c==0x21) {
ReadFile(hFileIn,&c,1,&dw,0);
if (c==0xF9) {
ReadFile(hFileIn,&ggce,sizeof(GIF_GRAPHIC_CONTROL_EXTENSION),&dw,0);
} else {
for (;;) {
ReadFile(hFileIn,&c,1,&dw,0);
if (!c) break;
SetFilePointer(hFileIn,c,0,FILE_CURRENT);
}
}
}
}
ggce.iBlockSize=4;
ggce.iDelayTime=(unsigned short)GetDlgItemInt(hMainDlg,IDC_EDIT_MAIN_DELAY,0,0);
ggce.iDisposalMethod=2;
c=(char)0x21;
WriteFile(hFileOut,&c,1,&dw,0);
c=(char)0xF9;
WriteFile(hFileOut,&c,1,&dw,0);
WriteFile(hFileOut,&ggce,sizeof(GIF_GRAPHIC_CONTROL_EXTENSION),&dw,0);
c=(char)0x2C;
WriteFile(hFileOut,&c,1,&dw,0);
WriteFile(hFileOut,&gid,sizeof(GIF_IMAGE_DESCRIPTOR),&dw,0);
WriteFile(hFileOut,szColorTable,iGctSize,&dw,0);
ReadFile(hFileIn,&c,1,&dw,0);
WriteFile(hFileOut,&c,1,&dw,0);
for (;;) {
ReadFile(hFileIn,&c,1,&dw,0);
WriteFile(hFileOut,&c,1,&dw,0);
if (!c) break;
ReadFile(hFileIn,szColorTable,c,&dw,0);
WriteFile(hFileOut,szColorTable,c,&dw,0);
}
CloseHandle(hFileIn);
}
c=(char)0x3B;
WriteFile(hFileOut,&c,1,&dw,0);
SetFilePointer(hFileOut,6,0,FILE_BEGIN);
WriteFile(hFileOut,&glsd1,sizeof(GIF_LOGICAL_SCREEN_DESCRIPTOR),&dw,0);
CloseHandle(hFileOut);
}
}
谢谢分享。。。。 回复 8# happytc
P版经常干这活?我没有听说过他会C++的? 回复 10# hzxymkb
美女,这是P版自己说的,不过他是改C的代码为au3 的UDF以供大家直接调用,造福大家
我们就需要P版这种助人为乐的人呀,把别的语言里经典函数改为au3的,毕竟au3很小众,相关函数肯定比象C/C++这种超语言少太多了。 回复 11# happytc
happytc还是很了解P版哦!
P版对AU3的功劳是没法说的! 谢谢楼主,au3好强大呀 的确强大!虽然是小众语言但用好了依然会发光的!谢谢楼主和众位高手! 我也在寻找。。。应该可以吧
页:
[1]