One way is to create an alphamask , you can find an interesting discussing here:
Code: Select all
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1
ofile=screengrab.png
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
bmap:=Gdip_BitmapFromScreen("100|100|300|200")
pBitmap :=Gdip_AlphaMask_rectangle(bmap,30,1)
Gdip_SaveBitmapToFile(pBitmap,oFile)
return
Gdip_AlphaMask_rectangle(source,r,bm) ; r radius rounded rectangle / set bm for bitmap=1 file=1
{
x:=y:=0
static _AlphaMask
If !_AlphaMask
{
MCode_AlphaMask := "518B4424249983E20303C28BC88B442428995383E20303C28B5424245556C1F902C1F802837C24400057757E85D20F8E0E01000"
. "08B5C241C8B74242C03C003C0894424388D048D000000000FAF4C2440034C243C894424348B4424208D3C888954244485F67E2C8B5424182B5424208"
. "BCF8BC38B2C0A332883C00481E5FFFFFF003368FC83C10483EE018969FC75E48B74242C037C2434035C2438836C24440175C15F5E5D33C05B59C385D"
. "20F8E900000008B5C241C8B74242C03C003C0894424388D048D000000000FAF4C2440034C243C894424348B442420895C24448D3C888954241085F67"
. "E428B5424182B5424208BC78BCBEB098DA424000000008BFF8B1981E3000000FFBD000000FF2BEB8B1C1081E3FFFFFF000BEB892883C10483C00483E"
. "E0175D98B74242C8B5C2444035C2438037C2434836C241001895C244475A35F5E5D33C05B59C3"
VarSetCapacity(_AlphaMask, StrLen(MCode_AlphaMask)//2)
Loop % StrLen(MCode_AlphaMask)//2 ;%
NumPut("0x" SubStr(MCode_AlphaMask, (2*A_Index)-1, 2), _AlphaMask, A_Index-1, "char")
}
if !bm
pBitmap_:=Gdip_CreateBitmapFromFile(source)
else
pBitmap_:=source
Gdip_GetDimensions(pBitmap_, w,h )
w1:=w+1
h1:=h+1
pBitmap := Gdip_CreateBitmap(w1,h1)
G_:= Gdip_GraphicsFromImage(pBitmap), Gdip_SetSmoothingMode(G_, 4), Gdip_SetInterpolationMode(G_, 7)
Gdip_DrawImage(G_, pBitmap_, 0, 0, w1,h1,0,0,w1,h1)
Gdip_DeleteGraphics(G_)
Gdip_DisposeImage(pBitmap_)
pBitmapMask := Gdip_CreateBitmap(w1, h1), G2 := Gdip_GraphicsFromImage(pBitmapMask),Gdip_SetSmoothingMode(G2, 4)
pBrush := Gdip_BrushCreateSolid(0xff00ff00)
Gdip_FillRoundedRectangle(G2, pBrush, 0, 0, w1, h1, r)
Gdip_DeleteBrush(pBrush)
Gdip_DeleteGraphics(G2)
pBitmapNew := Gdip_CreateBitmap(w1, h1)
If !pBitmapNew
Return -1
E1 := Gdip_LockBits(pBitmap, 0, 0, w1, h1, Stride1, Scan01, BitmapData1)
E2 := Gdip_LockBits(pBitmapMask, 0, 0, w1, h1, Stride2, Scan02, BitmapData2)
E3 := Gdip_LockBits(pBitmapNew, 0, 0, w1, h1, Stride3, Scan03, BitmapData3)
If (E1 || E2 || E3)
Return -2
E := DllCall(&_AlphaMask, "ptr", Scan01, "ptr", Scan02, "ptr", Scan03, "int", w, "int", h, "int", w, "int", h, "int", Stride1, "int", Stride2, "int", x, "int", y, "int", invert)
Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapMask, BitmapData2), Gdip_UnlockBits(pBitmapNew, BitmapData3)
Gdip_DisposeImage(pBitmap)
Gdip_DisposeImage(pBitmapMask)
Return (E = "") ? -3 : pBitmapNew
}