创建线性渐变位图.ahk
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=91899 #NoEnv #Warn #SingleInstance, Force SetWorkingDir, %A_ScriptDir% SetBatchLines, -1 SysColor := Format("0x{5:}{6:}{3:}{4:}{1:}{2:}", StrSplit(Format("{:06X}", DllCall("User32.dll\GetSysColor", "Int",15)))*) H := "HBITMAP:" Gui, New, -DPIScale, CreateGradient() Demo Gui, Margin, 20, 20 Gui, Add, Picture,, % H . CreateGradient(480, 1, 0x0, SysColor, 0x444444, 0x000000, 0x444444, SysColor) Gui, Add, Picture,, % H . CreateGradient(480, 1, 0x0, SysColor, 0x000044, 0x0000FF, 0x000044, SysColor) Gui, Add, Picture,, % H . CreateGradient(480, 1, 0x0, SysColor, 0xFF0000, 0x00FF00, 0x0000FF, SysColor) Gui, Add, Picture,, % H . CreateGradient(480, 1, 0x0, 0x0000FF, 0x00FF00, 0xFF0000, SysColor, SysColor, SysColor, 0xFF0000, 0x00FF00, 0x0000FF) Gui, Add, Picture,, % H . CreateGradient(480, 2, 0x0, 0x7F7F7F, 0x222222, 0x7F7F7F) Gui, Add, Picture,, % H . CreateGradient(480, 6, 0x0, 0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF) Gui, Add, Picture,, % H . CreateGradient(6, 100, 0x1, SysColor, 0x0000AA, 0x0000FF, 0x0000AA, SysColor) Gui, Add, Picture, x+m yp, % H . CreateGradient(37, 100, 0x1, 0x000000, 0xFFFFFF, 0x111111) Gui, Add, Picture, x+m yp, % H . CreateGradient(37, 100, 0x0, 0x000000, 0xFFFFFF, 0x111111) Gui, Add, Picture, x+m yp, % H . CreateGradient(100, 100, 0x1, 0x007F7F, 0x00AAAA, 0x00EEEE) Gui, Add, Picture, x+m yp, % H . CreateGradient(100, 100, 0x1, 0x7F7F00, 0xAAAA00, 0xFFFF00) Gui, Add, Picture, x+m yp, % H . CreateGradient(100, 100, 0x1, 0x7F007F, 0xAA00AA, 0xFF00FF) Gui, Add, Picture, xm, % H . CreateGradient(480, 50, 0x0 , 0xFF0000, 0xEE0000, 0xDD0000, 0xCC0000, 0xBB0000, 0xAA0000, 0x990000, 0x880000, 0x770000, 0x660000, 0x550000, 0x440000, 0x330000, 0x220000, 0x110000, 0x000000 , 0x001100, 0x002200, 0x003300, 0x004400, 0x005500, 0x006600, 0x007700, 0x008800, 0x009900, 0x00AA00, 0x00BB00, 0x00CC00, 0x00DD00, 0x00EE00, 0x00FF00 , 0x00EE00, 0x00DD00, 0x00CC00, 0x00BB00, 0x00AA00, 0x009900, 0x008800, 0x007700, 0x006600, 0x005500, 0x004400, 0x003300, 0x002200, 0x001100, 0x000000 , 0x000011, 0x000022, 0x000033, 0x000044, 0x000055, 0x000066, 0x000077, 0x000088, 0x000099, 0x0000AA, 0x0000BB, 0x0000CC, 0x0000DD, 0x0000EE, 0x0000FF) Gui, Show Return GuiClose: ExitApp CreateGradient(W, H, V:=0, Colors*) { ; by SKAN on D46L/D46L @ tiny.cc/creategradient Local N := ( Colors := Colors.Count()>1 ? Colors : [ 0, 16777215, 0 ] ).Count() , xOFF := (X := V ? W : 0) ? 0 : Ceil(W/(N-1)) , yOFF := (Y := V ? 0 : H) ? 0 : Ceil(H/(N-1)) , VarSetCapacity(VERT, N*16, 0) , VarSetCapacity(MESH, N*8, 0) Loop % ( N, pVert:=&VERT, pMesh:=&MESH ) X := V ? (X=0 ? W : X:=0) : X , Y := !V ? (Y=0 ? H : Y:=0) : Y , Color := Format("{:06X}", Colors[A_Index] & 0xFFFFFF) , Color := Format("0x{5:}{6:}00{3:}{4:}00{1:}{2:}00", StrSplit(Color)*) , pVert := NumPut(Color, NumPut(Y, NumPut(X, pVert+0, "Int"), "Int"), "Int64") , pMesh := NumPut(A_Index, NumPut(A_Index-1, pMesh+0, "Int"), "Int") , Z := V ? (Y += yOFF) : (X += xOFF) hBM := DllCall("Gdi32.dll\CreateBitmap", "Int",1, "Int",1, "Int",0x1, "Int",32, "PtrP",0, "Ptr") , hBM := DllCall("User32.dll\CopyImage", "Ptr",hBM, "Int",0x0, "Int",W, "Int",H, "Int",0x008, "Ptr") , mDC := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr",0, "Ptr") , DllCall("Gdi32.dll\SaveDC", "Ptr",mDC) , DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBM) , DllCall("Msimg32.dll\GradientFill", "Ptr",mDC, "Ptr",&VERT, "Int",N, "Ptr",&MESH, "Int",N-1, "Int",!!V) , DllCall("Gdi32.dll\RestoreDC", "Ptr",mDC, "Int",-1) , DllCall("Gdi32.dll\DeleteDC", "Ptr",mDC) Return hBM }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)