截图并以圆形保存.ahk
#NoEnv SetBatchLines -1 SetWorkingDir %A_ScriptDir% ; #Include <Gdip_all> destFile := "test.png" AntiAlias := 4, SRCAND := 0x008800C6 pToken := Gdip_Startup() pBitmap := Gdip_BitmapFromScreen("0|0|100|100") hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) hDcImage := CreateCompatibleDC() oBmImage := SelectObject(hDcImage, hBitmap) Gdip_GetImageDimensions(pBitmap, W, H) hBmMask := CreateDIBSection(W, H) hDcMask := CreateCompatibleDC() oBmMask := SelectObject(hDcMask, hBmMask) G := Gdip_GraphicsFromHDC(hDcMask) Gdip_SetSmoothingMode(G, AntiAlias) pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF) Gdip_FillEllipse(G, pBrush, 0, 0, W, H) Gdip_DeleteBrush(pBrush), Gdip_DeleteGraphics(G) BitBlt(hDcImage, 0, 0, W, H, hDcMask, 0, 0, SRCAND) SelectObject(hDcImage, oBmImage), SelectObject(hDcMask, oBmMask) DeleteDC(hDcImage), DeleteDC(hDcMask), DeleteObject(hBmMask) Gdip_DisposeImage(pBitmap) VarSetCapacity(BITMAP, size := 16 + A_PtrSize*2, 0) DllCall("GetObject", "Ptr", hBitmap, "UInt", size, "Ptr", &BITMAP) pPix := NumGet(BITMAP, 16 + A_PtrSize) pNewBimap := Gdip_CreateBitmap(W, H) Gdip_LockBits(pNewBimap, 0, 0, W, H, Stride, Scan0, data) Loop %H% DllCall("RtlMoveMemory", "Ptr", Scan0 + Stride*(H - A_Index), "Ptr", pPix + Stride*(A_Index - 1), "Ptr", Stride) Gdip_UnlockBits(pNewBimap, data) Gdip_SaveBitmapToFile(pNewBimap, destFile) Gui, +LastFound -Resize Gui, Add, Picture, , % "HBITMAP:*" hBitmap Gui, Show, AutoSize, Example Gdip_DisposeImage(pNewBimap), DeleteObject(hBitmap), Gdip_Shutdown(pToken) Return
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)