Library updated to 1.38
Thank you very much to
Learning one for pointing out an incorrect version number in 1.37 and also that Gdip_SaveBitmapToFile didnt work with AHK_L and for providing very clear examples of the error
Testing out more machine code, I have also added a box blur function (obviously thanks to Laszlo for adding the ability for me to write this into ahk):
The image is taken from a few pages back:
http://d.lanrentuku.com/down/png/0904/3 ... OS_002.png
Both code to save to disk or add to a gui:
Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA
hwnd1 := WinExist()
pBitmap1 := Gdip_CreateBitmapFromFile("Main_OS_002.png")
Width := Gdip_GetImageWidth(pBitmap1), Height := Gdip_GetImageHeight(pBitmap1)
pBitmap2 := Gdip_CloneBitmapArea(pBitmap1, 0, 0, Width, Height)
;hbm := CreateDIBSection(Width+20, Height+20), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
;G := Gdip_GraphicsFromHDC(hdc)
pBitmap := Gdip_CreateBitmap(Width+20, Height+20), G := Gdip_GraphicsFromImage(pBitmap)
E1 := Gdip_LockBits(pBitmap1, 0, 0, Width, Height, Stride1, Scan01)
MCode(Gdip_BoxBlurBitmap, MCode_BoxBlurBitmap())
DllCall(&Gdip_BoxBlurBitmap, "uint", Scan01, "int", Width, "int", Height, "int", Stride1, "int", 15)
Gdip_UnlockBits(pBitmap1)
Matrix = 0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0.7|0|0|0|0|0|1
Gdip_DrawImage(G, pBitmap1, 20, 20, Width, Height, 0, 0, Width, Height, Matrix)
Gdip_DisposeImage(pBitmap1)
Gdip_DrawImage(G, pBitmap2, 0, 0, Width, Height, 0, 0, Width, Height)
Gdip_DisposeImage(pBitmap2)
;UpdateLayeredWindow(hwnd1, hdc, (A_ScreenWidth-Width-20)//2, (A_ScreenHeight-Height-20)//2, Width+20, Height+20)
;SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_SaveBitmapToFile(pBitmap, "BoxBlurShadow.png")
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap)
OnMessage(0x201, "WM_LBUTTONDOWN")
return
;#######################################################################
MCode(ByRef code, hex)
{
VarSetCapacity(code, StrLen(hex)//2)
Loop % StrLen(hex)//2 ;%
NumPut("0x" SubStr(hex, 2*A_Index-1, 2), code, A_Index-1, "char")
}
;#######################################################################
WM_LBUTTONDOWN()
{
PostMessage, 0xA1, 2
}
;#######################################################################
CreateRect(ByRef Rect, x, y, w, h)
{
VarSetCapacity(Rect, 16)
NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
}
;#######################################################################
Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, LockMode = 3, PixelFormat = 0x26200a)
{
CreateRect(Rect, x, y, w, h)
VarSetCapacity(BitmapData, 21, 0)
E := DllCall("Gdiplus\GdipBitmapLockBits", "uint", pBitmap, "uint", &Rect, "uint", LockMode, "int", PixelFormat, "uint", &BitmapData)
Stride := NumGet(BitmapData, 8)
Scan0 := NumGet(BitmapData, 16)
return E
}
;#######################################################################
Gdip_UnlockBits(pBitmap)
{
return DllCall("Gdiplus\GdipBitmapUnlockBits", "uint", pBitmap, "uint", &BitmapData)
}
;#######################################################################
MCode_BoxBlurBitmap()
{
return "8B4C241433C083EC2C3BC80F8E4A0400008B5424385355568B7424480FAFD6578954242C894C2438EB06"
. "8D9B000000003BD0894424280F8EFE0100008B4C244083C102894C24308B54244433ED33DB33FF33F63BD08944241489442410894424"
. "500F8EBF0000008B4C243089542434900FB65101895424180FB6118954241C0FB651FF895424200FB651FE895424248B54241803D603"
. "D0B856555555F7EA8BC2C1E81F03C28B54241C88410103D703542450B856555555F7EA8BC2C1E81F03C28B542420880103D303542410"
. "B856555555F7EA8BC2C1E81F03C28B5424248841FF03D503542414B856555555F7EA8BC2C1E81F03C28841FE83C104836C2434018BC6"
. "8B742418897C24508B7C241C895C24108B5C2420896C24148B6C24240F854CFFFFFF33C08B4C24444933ED33DB33FF33F63BC8894424"
. "148944241089442450894C24340F8CD10000008B5424288D0C8A8B5424408D4C11028D9B000000000FB65101895424180FB611895424"
. "1C0FB651FF895424200FB651FE895424248B54241803D603D0B856555555F7EA8BC2C1E81F03C28B54241C88410103D703542450B856"
. "555555F7EA8BC2C1E81F03C28B542420880103D303542410B856555555F7EA8BC2C1E81F03C28B54242403D5035424148841FFB85655"
. "5555F7EA8BC2C1E81F03C28B5424348841FE4A83E9048BC68B742418897C24508B7C241C895C24108B5C2420896C24148B6C24248954"
. "243485D20F8D46FFFFFF33C08B4C24288B74244C8B54242C0174243003CE3BCA894C24280F8C0DFEFFFF8B7C24443BF80F8E06020000"
. "8B4C2448490FAFCE894C24308B4C244083C102897C24348D490033ED33DB33FF33F68944242889442414894424108944245085D20F8E"
. "C80000000FB6543101895424180FB614318954241C0FB65431FF895424200FB65431FE895424248B54241803D703D0B856555555F7EA"
. "8BC2C1E81F03C28B54241C8844310103D303542450B856555555F7EA8BC2C1E81F03C28B54242088043103D503542410B856555555F7"
. "EA8BC2C1E81F03C28B542424884431FF8B44242803D003542414B856555555F7EA8BC2C1E81F03C28B542428884431FE0374244C8954"
. "24143B74242C8B5424248BC78B7C2418895C24508B5C241C896C24108B6C2420895424280F8C38FFFFFF8B74243033C033ED33DB33FF"
. "3BF0894424288944241489442410894424500F8CCA0000008D6424000FB6543101895424180FB614318954241C0FB65431FF89542420"
. "0FB65431FE895424248B54241803D703D0B856555555F7EA8BC2C1E81F03C28B54241C8844310103D303542450B856555555F7EA8BC2"
. "C1E81F03C28B54242088043103D503542410B856555555F7EA8BC2C1E81F03C28B542424884431FF8B44242803D003542414B8565555"
. "55F7EA8BC2C1E81F03C28B542428884431FE2B74244C895424148B5424248BC78B7C2418895C24508B5C241C896C24108B6C24208954"
. "24280F893CFFFFFF33C08B54242C83C104836C2434010F8518FEFFFF8B74244C836C2438010F85D9FBFFFF5F5E5D5B83C42CC3"
}
;#######################################################################
Exit:
Gdip_Shutdown(pToken)
ExitApp
return
and c++ (it is written in a non-condensed way for speed improvements):
Code:
void Gdip_BoxBlurBitmap(unsigned char * Bitmap, int w, int h, int Stride, int Passes)
{
int A1, R1, G1, B1, A2, R2, G2, B2, A3, R3, G3, B3;
for (int i = 0; i < Passes; ++i)
{
for (int y = 0; y < h*Stride; y += Stride)
{
A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
for (int x = 0 ; x < w; ++x)
{
A3 = Bitmap[3+(4*x)+y];
R3 = Bitmap[2+(4*x)+y];
G3 = Bitmap[1+(4*x)+y];
B3 = Bitmap[(4*x)+y];
Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
Bitmap[(4*x)+y] = (B1+B2+B3)/3;
A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
}
A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
for (int x = w-1 ; x >= 0; --x)
{
A3 = Bitmap[3+(4*x)+y];
R3 = Bitmap[2+(4*x)+y];
G3 = Bitmap[1+(4*x)+y];
B3 = Bitmap[(4*x)+y];
Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
Bitmap[(4*x)+y] = (B1+B2+B3)/3;
A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
}
}
for (int x = 0; x < w; ++x)
{
A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
for (int y = 0; y < h*Stride; y += Stride)
{
A3 = Bitmap[3+(4*x)+y];
R3 = Bitmap[2+(4*x)+y];
G3 = Bitmap[1+(4*x)+y];
B3 = Bitmap[(4*x)+y];
Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
Bitmap[(4*x)+y] = (B1+B2+B3)/3;
A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
}
A1 = R1 = G1 = B1 = A2 = R2 = G2 = B2 = 0;
for (int y = (h-1)*Stride; y >= 0; y -= Stride)
{
A3 = Bitmap[3+(4*x)+y];
R3 = Bitmap[2+(4*x)+y];
G3 = Bitmap[1+(4*x)+y];
B3 = Bitmap[(4*x)+y];
Bitmap[3+(4*x)+y] = (A1+A2+A3)/3;
Bitmap[2+(4*x)+y] = (R1+R2+R3)/3;
Bitmap[1+(4*x)+y] = (G1+G2+G3)/3;
Bitmap[(4*x)+y] = (B1+B2+B3)/3;
A1 = A2; R1 = R2; G1 = G2; B1 = B2; A2 = A3; R2 = R3; G2 = G3; B2 = B3;
}
}
}
}