V1代码:
; 原版函数库出处:https://www.autohotkey.com/boards/viewtopic.php?t=72797 #NoEnv #SingleInstance Force SetBatchLines -1 SetWorkingDir %A_ScriptDir% Run https://image.baidu.com/search/index?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&dyTabStr=MCwxLDMsMiw2LDQsNSw4LDcsOQ%3D%3D&word=人脸 Loop 15 Outline%A_Index% := new HighlightOutline("Blue", 88) Loop FaceDetect("屏幕截图时随便填", 0, 0, A_ScreenWidth, A_ScreenHeight) Return ; MsgBox % FaceDetect("test.png") Esc::ExitApp FaceDetect(file, X:="", Y:="", W:="", H:="", maxheight := 2000) { static BitmapDecoderStatics, BitmapEncoderStatics, SoftwareBitmapStatics, FaceDetector, SupportedBitmapPixelFormats, countcoordinate if (FaceDetector = "") { CreateClass("Windows.Graphics.Imaging.BitmapDecoder", IBitmapDecoderStatics := "{438CCB26-BCEF-4E95-BAD6-23A822E58D01}", BitmapDecoderStatics) , CreateClass("Windows.Graphics.Imaging.BitmapEncoder", IBitmapEncoderStatics := "{A74356A7-A4E4-4EB9-8E40-564DE7E1CCB2}", BitmapEncoderStatics) , CreateClass("Windows.Graphics.Imaging.SoftwareBitmap", ISoftwareBitmapStatics := "{DF0385DB-672F-4A9D-806E-C2442F343E86}", SoftwareBitmapStatics) , CreateClass("Windows.Media.FaceAnalysis.FaceDetector", IFaceDetectorStatics := "{BC042D67-9047-33F6-881B-6746C1B218B8}", FaceDetectorStatics) , DllCall(NumGet(NumGet(FaceDetectorStatics+0)+6*A_PtrSize), "ptr", FaceDetectorStatics, "ptr*", FaceDetector) ; CreateAsync , WaitForAsync(FaceDetector) , DllCall(NumGet(NumGet(FaceDetectorStatics+0)+7*A_PtrSize), "ptr", FaceDetectorStatics, "ptr*", ReadOnlyList) ; GetSupportedBitmapPixelFormats , DllCall(NumGet(NumGet(ReadOnlyList+0)+7*A_PtrSize), "ptr", ReadOnlyList, "int*", count) ; count Loop % count DllCall(NumGet(NumGet(ReadOnlyList+0)+6*A_PtrSize), "ptr", ReadOnlyList, "int", A_Index-1, "uint*", BitmapPixelFormat) , SupportedBitmapPixelFormats .= "|" BitmapPixelFormat "|" ObjRelease(FaceDetectorStatics) , ObjRelease(ReadOnlyList) } if (W="") { if (SubStr(file, 2, 1) != ":") file := A_ScriptDir "\" file if !FileExist(file) or InStr(FileExist(file), "D") { msgbox File "%file%" does not exist ExitApp } VarSetCapacity(GUID, 16) , DllCall("ole32\CLSIDFromString", "wstr", IID_RandomAccessStream := "{905A0FE1-BC53-11DF-8C49-001E4FC686DA}", "ptr", &GUID) , DllCall("ShCore\CreateRandomAccessStreamOnFile", "wstr", file, "uint", Read := 0, "ptr", &GUID, "ptr*", IRandomAccessStream) } else VarSetCapacity(GUID, 16) , DllCall("ole32\CLSIDFromString", "wstr", IID_RandomAccessStream := "{905A0FE1-BC53-11DF-8C49-001E4FC686DA}", "ptr", &GUID) , hBitmap := HBitmapFromScreen(X, Y, W, H) , IRandomAccessStream := HBitmapToRandomAccessStream(hBitmap) , DllCall("DeleteObject", "Ptr", hBitmap) DllCall(NumGet(NumGet(BitmapDecoderStatics+0)+14*A_PtrSize), "ptr", BitmapDecoderStatics, "ptr", IRandomAccessStream, "ptr*", BitmapDecoder) ; CreateAsync , WaitForAsync(BitmapDecoder) , BitmapFrame := ComObjQuery(BitmapDecoder, IBitmapFrame := "{72A49A1C-8081-438D-91BC-94ECFC8185C6}") , DllCall(NumGet(NumGet(BitmapFrame+0)+12*A_PtrSize), "ptr", BitmapFrame, "uint*", width) ; get_PixelWidth , DllCall(NumGet(NumGet(BitmapFrame+0)+13*A_PtrSize), "ptr", BitmapFrame, "uint*", height) ; get_PixelHeight , DllCall(NumGet(NumGet(BitmapFrame+0)+8*A_PtrSize), "ptr", BitmapFrame, "uint*", BitmapPixelFormat) ; get_BitmapPixelFormat , BitmapFrameWithSoftwareBitmap := ComObjQuery(BitmapDecoder, IBitmapFrameWithSoftwareBitmap := "{FE287C9A-420C-4963-87AD-691436E08383}") if (height > maxheight) DllCall(NumGet(NumGet(BitmapEncoderStatics+0)+15*A_PtrSize), "ptr", BitmapEncoderStatics, "ptr", IRandomAccessStream, "ptr", BitmapDecoder, "ptr*", BitmapEncoder) ; CreateForTranscodingAsync , WaitForAsync(BitmapEncoder) , DllCall(NumGet(NumGet(BitmapEncoder+0)+15*A_PtrSize), "ptr", BitmapEncoder, "ptr*", BitmapTransform) ; BitmapTransform , DllCall(NumGet(NumGet(BitmapTransform+0)+7*A_PtrSize), "ptr", BitmapTransform, "int", floor(maxheight/height*width)) ; put_ScaledWidth , DllCall(NumGet(NumGet(BitmapTransform+0)+9*A_PtrSize), "ptr", BitmapTransform, "int", maxheight) ; put_ScaledHeight , DllCall(NumGet(NumGet(BitmapFrameWithSoftwareBitmap+0)+8*A_PtrSize), "ptr", BitmapFrameWithSoftwareBitmap, "uint", BitmapPixelFormat, "uint", Premultiplied := 0, "ptr", BitmapTransform, "uint", IgnoreExifOrientation := 0, "uint", DoNotColorManage := 0, "ptr*", SoftwareBitmap) ; GetSoftwareBitmapTransformedAsync else DllCall(NumGet(NumGet(BitmapFrameWithSoftwareBitmap+0)+6*A_PtrSize), "ptr", BitmapFrameWithSoftwareBitmap, "ptr*", SoftwareBitmap) ; GetSoftwareBitmapAsync WaitForAsync(SoftwareBitmap) if !InStr(SupportedBitmapPixelFormats, "|" BitmapPixelFormat "|") { DllCall(NumGet(NumGet(SoftwareBitmapStatics+0)+7*A_PtrSize), "ptr", SoftwareBitmapStatics, "ptr", SoftwareBitmap, "uint", Gray8 := 62, "ptr*", SoftwareBitmapTemp) ; Convert , Close := ComObjQuery(SoftwareBitmap, IClosable := "{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}") , DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), "ptr", Close) ; Close , ObjRelease(Close) , ObjRelease(SoftwareBitmap) , SoftwareBitmap := SoftwareBitmapTemp } DllCall(NumGet(NumGet(FaceDetector+0)+6*A_PtrSize), "ptr", FaceDetector, ptr, SoftwareBitmap, "ptr*", DetectedFaceList) ; DetectFacesAsync , WaitForAsync(DetectedFaceList) , DllCall(NumGet(NumGet(DetectedFaceList+0)+7*A_PtrSize), "ptr", DetectedFaceList, "int*", count) ; count Loop % countcoordinate Outline%A_Index%.Hide() Loop % count varsetcapacity(bounds, 16, 0) , DllCall(NumGet(NumGet(DetectedFaceList+0)+6*A_PtrSize), "ptr", DetectedFaceList, "int", A_Index-1, "ptr*", DetectedFace) ; get_Item , DllCall(NumGet(NumGet(DetectedFace+0)+6*A_PtrSize), "ptr", DetectedFace, "ptr", &bounds) ; BitmapBounds , x := numget(bounds, 0, "uint") , y := numget(bounds, 4, "uint") , width := numget(bounds, 8, "uint") , height := numget(bounds, 12, "uint") , result .= "face" A_Index ": x=" x ", y=" y ", width=" width ", height=" height "`n" , Outline%A_Index%.Show(x, y, width+x, height+y) , ObjRelease(DetectedFace) countcoordinate := count , Close := ComObjQuery(IRandomAccessStream, IClosable := "{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}") , DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), "ptr", Close) ; Close , ObjRelease(Close) , Close := ComObjQuery(SoftwareBitmap, IClosable := "{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}") , DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), "ptr", Close) ; Close , ObjRelease(Close) , ObjRelease(IRandomAccessStream) , ObjRelease(BitmapDecoder) , ObjRelease(BitmapFrame) if (height > maxheight) ObjRelease(BitmapEncoder), ObjRelease(BitmapTransform) ObjRelease(BitmapFrameWithSoftwareBitmap) , ObjRelease(SoftwareBitmap) , ObjRelease(DetectedFaceList) Return result } CreateClass(string, interface, ByRef Class) { CreateHString(string, hString) , VarSetCapacity(GUID, 16) , DllCall("ole32\CLSIDFromString", "wstr", interface, "ptr", &GUID) , result := DllCall("Combase.dll\RoGetActivationFactory", "ptr", hString, "ptr", &GUID, "ptr*", Class, "uint") if (result != 0) { if (result = 0x80004002) msgbox No such interface supported else if (result = 0x80040154) msgbox Class not registered else msgbox error: %result% ExitApp } DeleteHString(hString) } CreateHString(string, ByRef hString) { DllCall("Combase.dll\WindowsCreateString", "wstr", string, "uint", StrLen(string), "ptr*", hString) } DeleteHString(hString) { DllCall("Combase.dll\WindowsDeleteString", "ptr", hString) } WaitForAsync(ByRef Object) { AsyncInfo := ComObjQuery(Object, IAsyncInfo := "{00000036-0000-0000-C000-000000000046}") Loop { DllCall(NumGet(NumGet(AsyncInfo+0)+7*A_PtrSize), "ptr", AsyncInfo, "uint*", status) ; IAsyncInfo.Status if (status != 0) { if (status != 1) { DllCall(NumGet(NumGet(AsyncInfo+0)+8*A_PtrSize), "ptr", AsyncInfo, "uint*", ErrorCode) ; IAsyncInfo.ErrorCode msgbox AsyncInfo status error: %ErrorCode% ExitApp } ObjRelease(AsyncInfo) break } sleep 10 } DllCall(NumGet(NumGet(Object+0)+8*A_PtrSize), "ptr", Object, "ptr*", ObjectResult) ; GetResults , ObjRelease(Object) , Object := ObjectResult } ; =================== 截图和内存转换 =================== GetArea() { area := [] StartSelection(area) while !area.w Sleep, 100 Return area } StartSelection(area) { handler := Func("Select").Bind(area) Hotkey, LButton, % handler, On ReplaceSystemCursors("IDC_CROSS") } Select(area) { static hGui := CreateSelectionGui() Hook := new WindowsHook(WH_MOUSE_LL := 14, "LowLevelMouseProc", hGui) Loop { KeyWait, LButton WinGetPos, X, Y, W, H, ahk_id %hGui% } until w > 0 ReplaceSystemCursors("") Hotkey, LButton, Off Hook := "" Gui, %hGui%:Show, Hide for k, v in ["x", "y", "w", "h"] area[v] := %v% } ReplaceSystemCursors(IDC = "") { static IMAGE_CURSOR := 2, SPI_SETCURSORS := 0x57 , exitFunc := Func("ReplaceSystemCursors").Bind("") , SysCursors := { IDC_APPSTARTING: 32650 , IDC_ARROW : 32512 , IDC_CROSS : 32515 , IDC_HAND : 32649 , IDC_HELP : 32651 , IDC_IBEAM : 32513 , IDC_NO : 32648 , IDC_SIZEALL : 32646 , IDC_SIZENESW : 32643 , IDC_SIZENWSE : 32642 , IDC_SIZEWE : 32644 , IDC_SIZENS : 32645 , IDC_UPARROW : 32516 , IDC_WAIT : 32514 } if !IDC DllCall("SystemParametersInfo", UInt, SPI_SETCURSORS, UInt, 0, UInt, 0, UInt, 0) , OnExit(exitFunc, 0) else { hCursor := DllCall("LoadCursor", Ptr, 0, UInt, SysCursors[IDC], Ptr) for k, v in SysCursors hCopy := DllCall("CopyImage", Ptr, hCursor, UInt, IMAGE_CURSOR, Int, 0, Int, 0, UInt, 0, Ptr) , DllCall("SetSystemCursor", Ptr, hCopy, UInt, v) OnExit(exitFunc) } } CreateSelectionGui() { Gui, New, +hwndhGui +Alwaysontop -Caption +LastFound +ToolWindow +E0x20 -DPIScale WinSet, Transparent, 130 Gui, Color, FFC800 Return hGui } LowLevelMouseProc(nCode, wParam, lParam) { static WM_MOUSEMOVE := 0x200, WM_LBUTTONUP := 0x202 , coords := [], startMouseX, startMouseY, hGui , timer := Func("LowLevelMouseProc").Bind("timer", "", "") if (nCode = "timer") { while coords[1] { point := coords.RemoveAt(1) , mouseX := point[1], mouseY := point[2] , x := startMouseX < mouseX ? startMouseX : mouseX , y := startMouseY < mouseY ? startMouseY : mouseY , w := Abs(mouseX - startMouseX) , h := Abs(mouseY - startMouseY) try Gui, %hGUi%: Show, x%x% y%y% w%w% h%h% NA } } else { (!hGui && hGui := A_EventInfo) if (wParam = WM_LBUTTONUP) startMouseX := startMouseY := "" if (wParam = WM_MOUSEMOVE) { mouseX := NumGet(lParam + 0, "Int") , mouseY := NumGet(lParam + 4, "Int") if (startMouseX = "") { startMouseX := mouseX , startMouseY := mouseY } coords.Push([mouseX, mouseY]) SetTimer, % timer, -10 } Return DllCall("CallNextHookEx", Ptr, 0, Int, nCode, UInt, wParam, Ptr, lParam) } } class WindowsHook { __New(type, callback, eventInfo := "", isGlobal := true) { this.callbackPtr := RegisterCallback(callback, "Fast", 3, eventInfo) this.hHook := DllCall("SetWindowsHookEx", "Int", type, "Ptr", this.callbackPtr , "Ptr", !isGlobal ? 0 : DllCall("GetModuleHandle", "UInt", 0, "Ptr") , "UInt", isGlobal ? 0 : DllCall("GetCurrentThreadId"), "Ptr") } __Delete() { DllCall("UnhookWindowsHookEx", "Ptr", this.hHook) , DllCall("GlobalFree", "Ptr", this.callBackPtr, "Ptr") } } HBitmapFromScreen(X, Y, W, H) { HDC := DllCall("GetDC", "Ptr", 0, "UPtr") , HBM := DllCall("CreateCompatibleBitmap", "Ptr", HDC, "Int", W, "Int", H, "UPtr") , PDC := DllCall("CreateCompatibleDC", "Ptr", HDC, "UPtr") , DllCall("SelectObject", "Ptr", PDC, "Ptr", HBM) , DllCall("BitBlt", "Ptr", PDC, "Int", 0, "Int", 0, "Int", W, "Int", H, "Ptr", HDC, "Int", X, "Int", Y, "UInt", 0x00CC0020) , DllCall("DeleteDC", "Ptr", PDC) , DllCall("ReleaseDC", "Ptr", 0, "Ptr", HDC) Return HBM } HBitmapToRandomAccessStream(hBitmap) { static IID_IRandomAccessStream := "{905A0FE1-BC53-11DF-8C49-001E4FC686DA}" , IID_IPicture := "{7BF80980-BF32-101A-8BBB-00AA00300CAB}" , PICTYPE_BITMAP := 1 , BSOS_DEFAULT := 0 DllCall("Ole32\CreateStreamOnHGlobal", "Ptr", 0, "UInt", true, "PtrP", pIStream, "UInt") , VarSetCapacity(PICTDESC, sz := 8 + A_PtrSize*2, 0) , NumPut(sz, PICTDESC) , NumPut(PICTYPE_BITMAP, PICTDESC, 4) , NumPut(hBitmap, PICTDESC, 8) , riid := CLSIDFromString(IID_IPicture, GUID1) , DllCall("OleAut32\OleCreatePictureIndirect", "Ptr", &PICTDESC, "Ptr", riid, "UInt", false, "PtrP", pIPicture, "UInt") ; IPicture::SaveAsFile , DllCall(NumGet(NumGet(pIPicture+0) + A_PtrSize*15), "Ptr", pIPicture, "Ptr", pIStream, "UInt", true, "UIntP", size, "UInt") , riid := CLSIDFromString(IID_IRandomAccessStream, GUID2) , DllCall("ShCore\CreateRandomAccessStreamOverStream", "Ptr", pIStream, "UInt", BSOS_DEFAULT, "Ptr", riid, "PtrP", pIRandomAccessStream, "UInt") , ObjRelease(pIPicture) , ObjRelease(pIStream) Return pIRandomAccessStream } CLSIDFromString(IID, ByRef CLSID) { VarSetCapacity(CLSID, 16, 0) if res := DllCall("ole32\CLSIDFromString", "WStr", IID, "Ptr", &CLSID, "UInt") throw Exception("CLSIDFromString failed. Error: " . Format("{:#x}", res)) Return &CLSID } ; ====================== 边框高亮线 ====================== class HighlightOutline { __New(Color="Red", Transparent=255) { Loop 4 { Gui New, -Caption +AlwaysOnTop +ToolWindow HWNDhwnd -DPIScale +E0x20 +E0x00080000 Gui Color, %Color% DllCall("SetLayeredWindowAttributes", "Ptr", this[A_Index] := hwnd, "Uint", 0, "Uchar", Transparent, "int", 2) } this.top := this[1] , this.right := this[2] , this.bottom := this[3] , this.left := this[4] Gui Gui_Cheek_Number%A_DefaultGui%: Default } Show(x1, y1, x2, y2, b=3) { Try Gui % this[1] ":Show", % "NA x" x1-b " y" y1-b " w" x2-x1+b*2 " h" b Try Gui % this[2] ":Show", % "NA x" x2 " y" y1 " w" b " h" y2-y1 Try Gui % this[3] ":Show", % "NA x" x1-b " y" y2 " w" x2-x1+2*b " h" b Try Gui % this[4] ":Show", % "NA x" x1-b " y" y1 " w" b " h" y2-y1 } Hide() { Loop 4 Gui % this[A_Index] ": Hide" } Destroy() { Loop 4 Gui % this[A_Index] ": Destroy" } }
V2代码:
MsgBox FaceDetect("face.jpg") Facedetect(File, MaxHeight := 2000) { Static BitmapDecoderStatics, BitmapEncoderStatics, SoftwareBitmapStatics, FaceDetector := "", SupportedBitmapPixelFormats if (FaceDetector = "") { CreateClass("Windows.Graphics.Imaging.BitmapDecoder", IBitmapDecoderStatics := "{438CCB26-BCEF-4E95-BAD6-23A822E58D01}", &BitmapDecoderStatics) CreateClass("Windows.Graphics.Imaging.BitmapEncoder", IBitmapEncoderStatics := "{A74356A7-A4E4-4EB9-8E40-564DE7E1CCB2}", &BitmapEncoderStatics) CreateClass("Windows.Graphics.Imaging.SoftwareBitmap", ISoftwareBitmapStatics := "{DF0385DB-672F-4A9D-806E-C2442F343E86}", &SoftwareBitmapStatics) CreateClass("Windows.Media.FaceAnalysis.FaceDetector", IFaceDetectorStatics := "{BC042D67-9047-33F6-881B-6746C1B218B8}", &FaceDetectorStatics) ComCall(6, FaceDetectorStatics, 'Ptr*', &FaceDetector := 0) WaitForAsync(&FaceDetector) ComCall(7, FaceDetectorStatics, 'Ptr*', &ReadOnlyList := 0) ComCall(7, ReadOnlyList, 'Int*', &Count := 0) Loop Count { ComCall(6, ReadOnlyList, 'Int', A_Index - 1, 'UInt*', &BitmapPixelFormat := 0) SupportedBitmapPixelFormats .= "|" BitmapPixelFormat "|" } ObjRelease(FaceDetectorStatics) ObjRelease(ReadOnlyList) } if (SubStr(File, 2, 1) != ":") File := A_ScriptDir "\" File if !FileExist(File) || InStr(FileExist(File), "D") { MsgBox("File `"" File "`" does not exist") ExitApp() } GUID := Buffer(16) DllCall("ole32\CLSIDFromString", "wstr", IID_RandomAccessStream := "{905A0FE1-BC53-11DF-8C49-001E4FC686DA}", "Ptr", GUID) DllCall("ShCore\CreateRandomAccessStreamOnFile", "wstr", File, "UInt", Read := 0, "Ptr", GUID, "Ptr*", &IRandomAccessStream := 0) ComCall(14, BitmapDecoderStatics, 'Ptr', IRandomAccessStream, 'Ptr*', &BitmapDecoder := 0) WaitForAsync(&BitmapDecoder) BitmapFrame := ComObjQuery(BitmapDecoder, IBitmapFrame := "{72A49A1C-8081-438D-91BC-94ECFC8185C6}") ComCall(12, BitmapFrame, 'UInt*', &Width := 0) ComCall(13, BitmapFrame, 'UInt*', &Height := 0) ComCall(8, BitmapFrame, 'UInt*', &BitmapPixelFormat := 0) BitmapFrameWithSoftwareBitmap := ComObjQuery(BitmapDecoder, IBitmapFrameWithSoftwareBitmap := "{FE287C9A-420C-4963-87AD-691436E08383}") if (Height > MaxHeight) { ComCall(15, BitmapEncoderStatics, 'Ptr', IRandomAccessStream, 'Ptr', BitmapDecoder, 'Ptr*', &BitmapEncoder := 0) WaitForAsync(BitmapEncoder) ComCall(15, BitmapEncoder, 'Ptr*', &BitmapTransform := 0) ComCall(7, BitmapTransform, 'Int', Floor(MaxHeight / Height * Width)) ComCall(9, BitmapTransform, 'Int', MaxHeight) ComCall(8, BitmapFrameWithSoftwareBitmap, 'UInt', BitmapPixelFormat, 'UInt', Premultiplied := 0, 'Ptr', BitmapTransform, 'UInt', IgnoreExifOrientation := 0, 'UInt', DoNotColorManage := 0, 'Ptr*', &SoftwareBitmap) } else ComCall(6, BitmapFrameWithSoftwareBitmap, 'Ptr*', &SoftwareBitmap := 0) WaitForAsync(&SoftwareBitmap) if !InStr(SupportedBitmapPixelFormats, "|" BitmapPixelFormat "|") { ComCall(7, SoftwareBitmapStatics, 'Ptr', SoftwareBitmap, 'UInt', Gray8 := 62, 'Ptr*', &SoftwareBitmapTemp := 0) Close := ComObjQuery(SoftwareBitmap, IClosable := "{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}") ComCall(6, Close) SoftwareBitmap := SoftwareBitmapTemp } ComCall(6, FaceDetector, 'Ptr', SoftwareBitmap, 'Ptr*', &DetectedFaceList := 0) WaitForAsync(&DetectedFaceList) ComCall(7, DetectedFaceList, 'Int*', &Count := 0) Loop Count { VarSetStrCapacity(&bounds, 16) ComCall(6, DetectedFaceList, 'Int', A_Index-1, 'Ptr*', &DetectedFace := 0) ComCall(6, DetectedFace, 'Ptr', StrPtr(bounds)) x := NumGet(StrPtr(bounds), 0, "UInt") y := NumGet(StrPtr(bounds), 4, "UInt") Width := NumGet(StrPtr(bounds), 8, "UInt") Height := NumGet(StrPtr(bounds), 12, "UInt") Result .= "face" A_Index ": x=" x ", y=" y ", Width=" Width ", Height=" Height "`n" ObjRelease(DetectedFace) } Close := ComObjQuery(IRandomAccessStream, IClosable := "{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}") ComCall(6, Close) Close := ComObjQuery(SoftwareBitmap, IClosable := "{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}") ComCall(6, Close) ObjRelease(IRandomAccessStream) ObjRelease(BitmapDecoder) if (Height > MaxHeight) { ObjRelease(BitmapEncoder) ObjRelease(BitmapTransform) } ObjRelease(SoftwareBitmap) ObjRelease(DetectedFaceList) Return Result } CreateClass(string, interface, &Class) { CreateHString(string, &hString) GUID := Buffer(16) DllCall("ole32\CLSIDFromString", "wstr", interface, "Ptr", GUID) Result := DllCall("Combase.dll\RoGetActivationFactory", "Ptr", hString, "Ptr", GUID, "Ptr*", &Class := 0, "UInt") if (Result != 0) { if (Result = 0x80004002) MsgBox("No such interface supported") else if (Result = 0x80040154) MsgBox("Class not registered") else MsgBox("error: " Result) } DeleteHString(hString) } CreateHString(string, &hString) { DllCall("Combase.dll\WindowsCreateString", "wstr", string, "UInt", StrLen(string), "Ptr*", &hString := 0) } DeleteHString(hString) { DllCall("Combase.dll\WindowsDeleteString", "Ptr", hString) } WaitForAsync(&Object) { AsyncInfo := ComObjQuery(Object, IAsyncInfo := "{00000036-0000-0000-C000-000000000046}") Loop { ComCall(7, Asyncinfo, 'UInt*', &Status := 0) if (Status != 0) { if (Status != 1) { ComCall(8, Asyncinfo, 'UInt*', &ErrorCode := 0) MsgBox("AsyncInfo Status error: " ErrorCode) } Break } Sleep(10) } ComCall(8, Object, 'Ptr*', &ObjectResult := 0) ObjRelease(Object) Object := ObjectResult }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)