Eine weitere GdiPlus-Spielerei...
Diesmal: gebürstetes Aluminium
autoit.de/wcf/attachment/15549/
Im Prinzip sind es nur 3 Schritte:
1 Schritt: Noise erstellen; zufällige Grautöne für jeden Pixel der Bitmap; wegen der Geschwindigkeit wird nur ein kleines NoiseBitmap erstellt und dann wiederholt
Das Ergebnis ist zwar nicht so schön, aber AutoIt ist etwas zu langsam, als dass man das gesammte Bild "noisen" könnte...
(Ein besseres Ergebnis hätte man vielleicht noch mit "Gaussian noise")
2 Schritt: MotionBlur; verwandlelt die Grautonpixel zu Linien
Der Effekt ergibt sich einfach, indem das Bild transparent mit einem immer größeren X-Offset wiederholt wird.
(Ist warscheinlich der schlechteste Algo, aber auch der schnellste
3 Schritt: Lichtreflexion; ein Verlauf von Transparent zu Weiß wird darübergezeichnent
-fertig
Spoiler anzeigen
#include <GDIPlus.au3>
#include <GDIPlusConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $iWidth = 1200
Global $iHeight = 600
_GDIPlus_Startup()
Global $hGui = GUICreate("GDIPlus Script by Eukalyptus", $iWidth, $iHeight)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Global $hDC = _WinAPI_GetDC($hGui)
Global $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
Global $hBmpTmp = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
_WinAPI_DeleteObject($hBMP)
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmpTmp)
_GDIPlus_BitmapDispose($hBmpTmp)
Global $hCDC = _WinAPI_CreateCompatibleDC($hDC)
Global $hOBJ = _WinAPI_SelectObject($hCDC, $hBMP)
Global $hGfxBuffer = _GDIPlus_GraphicsCreateFromHDC($hCDC)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFFFFFFFF)
GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_PAINT")
GUISetState()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Global $hBitmap = _CreateBackground()
[/autoit] [autoit][/autoit] [autoit]_Draw()
While 1
Sleep(10)
WEnd
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _CreateBackground()
Local $hBitmap_ALU = _CreateBrushedAluminum($iWidth, $iHeight)
Local $hBitmap_ALU2 = _CreateBrushedAluminum($iWidth, $iHeight, 14, 0.6, 0.2, 0.2, 0.2, 0x33FFFFFF)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False)
Local $hBitmap = $aResult[6]
Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hContext, "int", 7)
_GDIPlus_GraphicsDrawImage($hContext, $hBitmap_ALU, 0, 0)
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 3, False)
Local $hPath = $aResult[2]
Local $hFormat = _GDIPlus_StringFormatCreate()
Local $hFamily = _GDIPlus_FontFamilyCreate("Arial Black")
_PathAddText($hPath, "Brushed", $hFamily, $hFormat, 100, 40)
_PathAddText($hPath, "Aluminium", $hFamily, $hFormat, 100)
_PathAddText($hPath, "AutoIt GdiPlus Script", $hFamily, $hFormat, 50, 80)
$aResult = DllCall($ghGDIPDll, "uint", "GdipClonePath", "hwnd", $hPath, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 3, False)
Local $hPath_Clone = $aResult[2]
Local $hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, 2, 2)
DllCall($ghGDIPDll, "uint", "GdipTransformPath", "hwnd", $hPath_Clone, "hwnd", $hMatrix)
Local $hBrush = _GDIPlus_BrushCreateSolid(0x44FFFFFF)
DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hContext, "hwnd", $hBrush, "hwnd", $hPath_Clone)
_GDIPlus_MatrixTranslate($hMatrix, -5, -5)
DllCall($ghGDIPDll, "uint", "GdipTransformPath", "hwnd", $hPath_Clone, "hwnd", $hMatrix)
_GDIPlus_BrushSetSolidColor($hBrush, 0x88000000)
DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hContext, "hwnd", $hBrush, "hwnd", $hPath_Clone)
_GDIPlus_MatrixDispose($hMatrix)
DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath_Clone)
_GDIPlus_BrushDispose($hBrush)
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hBitmap_ALU2, "int", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 2, False)
$hBrush = $aResult[3]
DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hContext, "hwnd", $hBrush, "hwnd", $hPath)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)
_GDIPlus_BrushDispose($hBrush)
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_BitmapDispose($hBitmap_ALU)
_GDIPlus_BitmapDispose($hBitmap_ALU2)
Return $hBitmap
EndFunc ;==>_CreateBackground
Func _PathAddText($hPath, $sText, $hFamily, $hFormat, $fSize, $fYOff = 0)
Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
Local $tBounds = _GDIPlus_RectFCreate(0, 0, 0, 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False)
Local $hPath_Tmp = $aResult[2]
DllCall($ghGDIPDll, "uint", "GdipAddPathString", "hwnd", $hPath_Tmp, "wstr", $sText, "int", -1, "hwnd", $hFamily, "int", 1, "float", $fSize, "ptr", DllStructGetPtr($tLayout), "hwnd", $hFormat)
DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath_Tmp, "ptr", DllStructGetPtr($tBounds), "hwnd", 0, "hwnd", 0)
DllStructSetData($tLayout, "X", ($iWidth / 2) - (DllStructGetData($tBounds, "Width") / 2) - DllStructGetData($tBounds, "X"))
DllCall($ghGDIPDll, "uint", "GdipGetPathWorldBounds", "hwnd", $hPath, "ptr", DllStructGetPtr($tBounds), "hwnd", 0, "hwnd", 0)
DllStructSetData($tLayout, "Y", DllStructGetData($tBounds, "Y") + DllStructGetData($tBounds, "Height") + $fYOff)
DllCall($ghGDIPDll, "uint", "GdipAddPathString", "hwnd", $hPath, "wstr", $sText, "int", -1, "hwnd", $hFamily, "int", 1, "float", $fSize, "ptr", DllStructGetPtr($tLayout), "hwnd", $hFormat)
[/autoit] [autoit][/autoit] [autoit]DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath_Tmp)
EndFunc ;==>_PathAddText
Func _Draw()
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
_GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBitmap, 0, 0)
[/autoit] [autoit][/autoit] [autoit]_WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hCDC, 0, 0, 0x00CC0020)
EndFunc ;==>_Draw
Func _CreateBrushedAluminum($iW, $iH, $iBlurDist = 14, $fBlurTrans = 0.6, $fRed = 0.8, $fGreen = 0.9, $fBlue = 1, $iLightColor = 0xAAFFFFFF, $fLightAngle = -8, $fLightSigma = 0.48, $fLightScale = 0.83)
$iBlurDist = Ceiling($iBlurDist)
$iBlurDist += 1 - Mod($iBlurDist, 2)
Local $iOverSize = 0
For $i = 1 To $iBlurDist Step 2
$iOverSize += $i + $i + 1
Next
Local $iWO = $iW + $iOverSize
[/autoit] [autoit][/autoit] [autoit];=========================================
; Add Noise
;=========================================
Local $iNoiseSize = 40
[/autoit] [autoit][/autoit] [autoit]Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iNoiseSize, "int", $iNoiseSize, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 1, False)
Local $hBmp_Noise = $aResult[6]
Local $hGfx_Noise = _GDIPlus_ImageGetGraphicsContext($hBmp_Noise)
Local $tData = _GDIPlus_BitmapLockBits($hBmp_Noise, 0, 0, $iNoiseSize, $iNoiseSize, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
Local $iStride = DllStructGetData($tData, "Stride")
Local $iWidth = DllStructGetData($tData, "Width")
Local $iHeight = DllStructGetData($tData, "Height")
Local $pScan0 = DllStructGetData($tData, "Scan0")
Local $tPixel = DllStructCreate("dword[" & $iWidth * $iHeight & "];", $pScan0)
Local $iAmp
For $row = 0 To $iHeight - 1
For $col = 0 To $iWidth - 1
$iAmp = Random(0, 0xFF, 1)
DllStructSetData($tPixel, 1, BitOR(0xFF000000, BitShift($iAmp, -16), BitShift($iAmp, -8), $iAmp), $row * $iWidth + $col + 1)
Next
Next
_GDIPlus_BitmapUnlockBits($hBmp_Noise, $tData)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit];=========================================
; Create Full NoiseBitmap
;=========================================
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWO, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 3, False)
Local $hBmp_Full = $aResult[6]
Local $hGfx_Full = _GDIPlus_ImageGetGraphicsContext($hBmp_Full)
_GDIPlus_GraphicsSetSmoothingMode($hGfx_Full, 2)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGfx_Full, "int", 7)
Local $iXOff, $iYOff, $iSizeX, $iSizeY
For $y = 0 To $iH Step $iNoiseSize / 2
For $x = 0 To $iWO Step $iNoiseSize / 2
$iXOff = Random(0, $iNoiseSize / 2, 1)
$iYOff = Random(0, $iNoiseSize / 2, 1)
$iSizeX = $iNoiseSize - $iXOff
$iSizeY = $iNoiseSize - $iYOff
_GDIPlus_GraphicsDrawImageRectRect($hGfx_Full, $hBmp_Noise, $iXOff, $iYOff, $iSizeX, $iSizeY, $x, $y, $iSizeX, $iSizeY)
Next
Next
_GDIPlus_GraphicsDispose($hGfx_Noise)
_GDIPlus_BitmapDispose($hBmp_Noise)
;=========================================
; MotionBlur
;=========================================
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWO, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 3, False)
Local $hBmp_Full2 = $aResult[6]
Local $hGfx_Full2 = _GDIPlus_ImageGetGraphicsContext($hBmp_Full2)
_GDIPlus_GraphicsSetSmoothingMode($hGfx_Full2, 2)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGfx_Full2, "int", 7)
Local $tColorMatrix = DllStructCreate("float[5]; float[5]; float[5]; float[5]; float[5];")
DllStructSetData($tColorMatrix, 1, 1, 1)
DllStructSetData($tColorMatrix, 2, 1, 2)
DllStructSetData($tColorMatrix, 3, 1, 3)
DllStructSetData($tColorMatrix, 4, $fBlurTrans, 4)
DllStructSetData($tColorMatrix, 5, 1, 5)
$aResult = DllCall($ghGDIPDll, "int", "GdipCreateImageAttributes", "ptr*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 4, False)
Local $hImgAttrib = $aResult[1]
DllCall($ghGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr", $hImgAttrib, "int", 1, "int", 1, "ptr", DllStructGetPtr($tColorMatrix), "ptr", 0, "int", 0)
For $i = 1 To $iBlurDist Step 2
DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "hwnd", $hGfx_Full2, "hwnd", $hBmp_Full, "int", $i, "int", 0, "int", $iWO, "int", $iH, "int", 0, "int", 0, "int", $iWO, "int", $iH, "int", 2, "ptr", $hImgAttrib, "int", 0, "int", 0)
If $i >= $iBlurDist Then
DllStructSetData($tColorMatrix, 1, $fRed, 1)
DllStructSetData($tColorMatrix, 2, $fGreen, 2)
DllStructSetData($tColorMatrix, 3, $fBlue, 3)
DllStructSetData($tColorMatrix, 4, 1, 4)
DllCall($ghGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr", $hImgAttrib, "int", 1, "int", 1, "ptr", DllStructGetPtr($tColorMatrix), "ptr", 0, "int", 0)
EndIf
DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "hwnd", $hGfx_Full, "hwnd", $hBmp_Full2, "int", $i + 1, "int", 0, "int", $iWO, "int", $iH, "int", 0, "int", 0, "int", $iWO, "int", $iH, "int", 2, "ptr", $hImgAttrib, "int", 0, "int", 0)
Next
DllCall($ghGDIPDll, "int", "GdipDisposeImageAttributes", "ptr", $hImgAttrib)
_GDIPlus_GraphicsDispose($hGfx_Full2)
_GDIPlus_BitmapDispose($hBmp_Full2)
_GDIPlus_GraphicsDispose($hGfx_Full)
;=========================================
; Add Light
;=========================================
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 3, False)
Local $hBmp_Alu = $aResult[6]
Local $hGfx_Alu = _GDIPlus_ImageGetGraphicsContext($hBmp_Alu)
_GDIPlus_GraphicsSetSmoothingMode($hGfx_Alu, 2)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGfx_Alu, "int", 7)
_GDIPlus_GraphicsDrawImage($hGfx_Alu, $hBmp_Full, -$iOverSize, 0)
_GDIPlus_BitmapDispose($hBmp_Full)
Local $tPointF1 = DllStructCreate("float; float;")
Local $tPointF2 = DllStructCreate("float; float;")
DllStructSetData($tPointF2, 2, $iH * $fLightScale)
$aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", DllStructGetPtr($tPointF1), "ptr", DllStructGetPtr($tPointF2), "uint", 0, "uint", $iLightColor, "int", 0, "int*", 0)
If @error Or Not IsArray($aResult) Then Return SetError(1, 4, False)
Local $hBrush = $aResult[6]
DllCall($ghGDIPDll, "uint", "GdipSetLineSigmaBlend", "hwnd", $hBrush, "float", $fLightSigma, "float", 1)
DllCall($ghGDIPDll, "uint", "GdipSetLineGammaCorrection", "hwnd", $hBrush, "int", True)
DllCall($ghGDIPDll, "uint", "GdipRotateLineTransform", "hwnd", $hBrush, "float", $fLightAngle, "int", 0)
_GDIPlus_GraphicsFillRect($hGfx_Alu, 0, 0, $iW, $iH, $hBrush)
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGfx_Alu)
Return $hBmp_Alu
EndFunc ;==>_CreateBrushedAluminum
Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
_WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hCDC, 0, 0, 0x00CC0020)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_PAINT
Func _Exit()
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGfxBuffer)
_WinAPI_SelectObject($hCDC, $hOBJ)
_WinAPI_DeleteObject($hBMP)
_WinAPI_DeleteDC($hCDC)
_WinAPI_ReleaseDC($hGui, $hDC)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_Exit
E