#include <APIConstants.au3>
#include <GDIP.au3>
#include <WinAPIEx.au3>
_GDIPlus_Startup()
$hForm = GUICreate('MyGUI', 360, 360, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetState()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Test.png')
;~ $hPreview = _GDIPlus_ImageCreatePreview($hImage, 1, 3, 0, 400, 300)
$hPreview = _GDIPlus_ImageCreatePreview($hImage, 1, 3, 1)
If Not $hPreview Then Exit
_GDIPlus_ImageShowPreview($hForm, $hPreview, 1, 200)
Do
Until GUIGetMsg() = -3
Func _GDIPlus_ImageCreatePreview($hImage, $fDelete = 0, $iFrameMode = -1, $iAutoAdjustSize = 1, $iWidth = -1, $iHeight = -1)
Local $aSize = _GDIPlus_ImageGetDimension($hImage)
If Not IsArray($aSize) Then Return 0
If $iAutoAdjustSize Then
Local Const $iMin = 128, $iMax = 512
Local $aTmpSize = $aSize, $aK[2] = [1, 1]
For $i = 0 To 1
If $aTmpSize[$i] > $iMax Then
$aK[$i] = $iMax / $aTmpSize[$i]
EndIf
Next
For $i = 0 To 1
If $aK[1] > $aK[0] Then
$aTmpSize[$i] *= $aK[0]
Else
$aTmpSize[$i] *= $aK[1]
EndIf
If $aTmpSize[$i] < $iMin Then $aTmpSize[$i] = $iMin
Next
$iWidth = $aTmpSize[0] + 36
$iHeight = $aTmpSize[1] + 36
EndIf
Local $aPart[4][5] = [[17, 5, $iWidth - 34, 12, -90], [$iWidth - 17, 17, 12, $iHeight - 34, 0], [17, $iHeight - 17, $iWidth - 34, 12, 90], [5, 17, 12, $iHeight - 34, 180]]
Local $aK[2] = [1, 1]
Local $aSize, $tRect, $hGraphics, $hBrush, $hPen, $hPreview
If ($iWidth - 36) < $aSize[0] Then
$aK[0] = ($iWidth - 36) / $aSize[0]
EndIf
If ($iHeight - 36) < $aSize[1] Then
$aK[1] = ($iHeight - 36) / $aSize[1]
EndIf
For $i = 0 To 1
If $aK[1] > $aK[0] Then
$aSize[$i] *= $aK[0]
Else
$aSize[$i] *= $aK[1]
EndIf
Next
$hPreview = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hPreview)
_GDIPlus_GraphicsClear($hGraphics, 0)
$hBrush = _GDIPlus_BrushCreateSolid(0x28000000)
_GDIPlus_GraphicsFillRect($hGraphics, 17, 17, $iWidth - 34, $iHeight - 34, $hBrush)
_GDIPlus_BrushDispose($hBrush)
$hBrush = _GDIPlus_HatchBrushCreate($HatchStyleLargeCheckerBoard, 0xFFFFFFFF, 0xFFEBEBEB)
_GDIPlus_GraphicsFillRect($hGraphics, 18, 18, $iWidth - 36, $iHeight - 36, $hBrush)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, Round(($iWidth - $aSize[0]) / 2), Round(($iHeight - $aSize[1]) / 2), $aSize[0], $aSize[1])
_GDIPlus_BrushDispose($hBrush)
Local $iFrameWidth = 1, $iFrameColor = 0x606060
Switch $iFrameMode
Case 2, 3 ;Shadow (3 with inner frame, 2 without it)
_GDIPlus_GraphicsDrawRadialGradient($hGraphics, 17, 17, 12, 0x28000000, 0, -180, -90)
_GDIPlus_GraphicsDrawRadialGradient($hGraphics, $iWidth - 17, 17, 12, 0x28000000, 0, -90, 0)
_GDIPlus_GraphicsDrawRadialGradient($hGraphics, $iWidth - 17, $iHeight - 17, 12, 0x28000000, 0, 0, 90)
_GDIPlus_GraphicsDrawRadialGradient($hGraphics, 17, $iHeight - 17, 12, 0x28000000, 0, 90, 180)
For $i = 0 To 3
$tRect = DllStructCreate($tagGDIPRECTF)
For $j = 0 To 4
DllStructSetData($tRect, $j + 1, $aPart[$i][$j])
Next
$hBrush = _GDIPlus_LineBrushCreateFromRectWithAngle($tRect, 0x28000000, 0, $aPart[$i][4], 0, 3)
_GDIPlus_GraphicsFillRect($hGraphics, $aPart[$i][0], $aPart[$i][1], $aPart[$i][2], $aPart[$i][3], $hBrush)
_GDIPlus_BrushDispose($hBrush)
Next
If $iFrameMode = 3 Then ContinueCase
Case 1 ;Simple frame
$hPen = _GDIPlus_PenCreate('0xFF' & Hex($iFrameColor, 6), $iFrameWidth, 2)
_GDIPlus_GraphicsDrawRect($hGraphics, 17, 17, $iWidth - 35, $iHeight - 35, $hPen)
_GDIPlus_PenDispose($hPen)
Case 0 ;No frame (Default)
EndSwitch
_GDIPlus_GraphicsDispose($hGraphics)
If ($hPreview) And ($fDelete) Then
_GDIPlus_ImageDispose($hImage)
EndIf
Return $hPreview
EndFunc
Func _GDIPlus_ImageShowPreview($hWnd, $hPreview, $fDelete = 0, $iSpeed = 100, $iX = -1, $iY = -1)
Local $iW, $iH, $aSize, $iTimer, $iDelay, $hGraphics, $hImage
If Not IsHWnd($hWnd) Then Return 0
$aSize = _GDIPlus_ImageGetDimension($hPreview)
If Not IsArray($aSize) Then Return 0
If ($iX <> -1) And ($iY <> -1) Then
$iX -= $aSize[0] / 2
$iY -= $aSize[1] / 2
EndIf
$hImage = _GDIPlus_BitmapCreateFromScan0($aSize[0], $aSize[1])
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)
For $i = 15 To 255 Step 40
$iTimer = TimerInit()
If $i = 255 Then
$iW = $aSize[0]
$iH = $aSize[1]
Else
$iW = Round($aSize[0] * Sin(2 * ATan(1) * $i / 255))
If Mod($iW, 2) Then $iW += 1
$iH = Round($aSize[1] * Sin(2 * ATan(1) * $i / 255))
If Mod($iH, 2) Then $iH += 1
EndIf
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hPreview, ($aSize[0] - $iW) / 2, ($aSize[1] - $iH) / 2, $iW, $iH)
_WinAPI_UpdateLayeredWindowEx($hWnd, $iX, $iY, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage), $i, 1)
$iDelay = $iSpeed / 7 - TimerDiff($iTimer)
If $iDelay < 0 Then $iDelay = 0
$iTimer = TimerInit()
Do
Until TimerDiff($iTimer) >= $iDelay
Next
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_ImageDispose($hImage)
If $fDelete Then
_GDIPlus_ImageDispose($hPreview)
EndIf
Return 1
EndFunc
Func _GDIPlus_GraphicsDrawRadialGradient($hGraphics, $iX, $iY, $iRadius, $iARGB1, $iARGB2, $iStartAngle = 0, $iEndAngle = 360, $iStep = 5)
If $iStep < 1 Then $iStep = 1
Local $Xi = $iX - $iRadius, $Yi = $iY - $iRadius, $Di = 2 * $iRadius
Local $hBrush, $hMatrix, $Smooth = _GDIPlus_GraphicsGetSmoothingMode($hGraphics)
Local $iStart = True
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 0)
$hBrush = _GDIPlus_LineBrushCreate(0, 0, $iRadius, 0, $iARGB1, $iARGB2, 3)
$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, $iX, $iY)
While $iStartAngle < $iEndAngle
If $iStartAngle + $iStep > $iEndAngle Then
$iStep = $iEndAngle - $iStartAngle
EndIf
If $iStart Then
_GDIPlus_MatrixRotate($hMatrix, $iStartAngle + $iStep / 2)
$iStart = False
Else
_GDIPlus_MatrixRotate($hMatrix, $iStep)
EndIf
_GDIPlus_LineBrushSetTransform($hBrush, $hMatrix)
_GDIPlus_GraphicsFillPie($hGraphics, $Xi, $Yi, $Di, $Di, $iStartAngle, $iStep, $hBrush)
$iStartAngle += $iStep
WEnd
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, $Smooth)
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_BrushDispose($hBrush)
Return 1
EndFunc