Sign in to follow this  
Followers 0
Skitty

Gravitational lensing effect on image?

8 posts in this topic

#1 ·  Posted (edited)

So I've been playing with some code I've got, most of which was ripped from UEZ and created some miscellaneous useless scripts and suddenly I felt compelled to find a way to add en effect to an image that would make it look like if there is a black hole in your desktop.

I've searched and searched to no avail and now I'm here. Anyone know how to add an effect to an image as picture related?

Posted Image

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%%scriptfile%_Obfuscated.au3"
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#Include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>

HotKeySet("{ESC}","close")

Global $Img = @ScriptDir&"test.png"
Global $aM_Mask, $GUI, $hwnd
Global $IMAGE_BITMAP = 0
Global $STM_SETIMAGE = 0x0172
Init()
Func Init()
_GDIPlus_Startup()
Local $hwnd = GUICreate("Test", 300, 300, -1, -1,$WS_POPUP,-1,GUICreate("ghost"));$WS_EX_TOPMOST
GUICtrlCreatePic("",0,0,400,400,-1,0x00100000); only for enable dragging of the gui
GUISetBkColor(0x000000,$hwnd)
_ScreenCapture_CaptureWnd($Img,$hwnd);leaving the courser...
GUISetState()
Local $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
Local $bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
Local $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
Local $Pos = WinGetPos($hwnd)
Local $TmpPos = $Pos
Local $image = _GDIPlus_ImageLoadFromFile($Img)
Local $matrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($matrix, 150, 150);True)
setTrans($hwnd)
Do
  $Pos = WinGetPos($hwnd)
  If ($Pos[0] <> $TmpPos[0]) Or ($Pos[1] <> $TmpPos[1]) Then
   GUISetState(@SW_HIDE)
   _GDIPlus_BitmapDispose($image)
   Sleep(100)
   _ScreenCapture_CaptureWnd($Img,$hwnd);leaving the courser..
   $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
   $bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
   $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
   $image = _GDIPlus_ImageLoadFromFile($Img)
   $matrix = _GDIPlus_MatrixCreate()
   _GDIPlus_MatrixTranslate($matrix, 150, 150);True)
   GUISetState(@SW_SHOW)
   $Pos = WinGetPos($hwnd)
   $TmpPos = $Pos
  EndIf
  ;_GDIPlus_MatrixRotate($matrix, 0.01)
  _GDIPlus_GraphicsSetTransform($backbuffer, $matrix)
  _GDIPlus_GraphicsDrawImageRect($backbuffer, $image, -150, -150, 300, 300);-150,-150)
  _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 300, 300)
  Sleep(20)
Until 0

Return
EndFunc
Func close()
    Exit
EndFunc  ;==>close
Func setTrans($hW)
Local $x, $Startx, $Endx
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)

    For $y = 0 To 300
        $x = Abs((150 * 150 - (150 - $y) * (150 - $y)) ^ 0.5)
        $Startx = 150 + $x
        $Endx = 300
        addRegion($Startx, $y, $Endx, $y)
        $Startx = 0
        $Endx = 150 - $x
        addRegion($Startx, $y, $Endx, $y)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hW, "long", $aM_Mask[0], "int", 1)
EndFunc  ;==>setTrans
Func addRegion($a, $b, $c, $d)
    Local $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $a, "long", $b, "long", $c + 1, "long", $d + 1)
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc  ;==>addRegion

Edit: forgot to explain the script, the script basically takes a snapshot of the background area of where the gui is going to appear and then loads the image to the gui, which is a big circle really, I want to find a way of making the picture look a little warped before adding it to the gui so it will have a black hole effect or something.

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You could use ImageMagick...

$img = ObjCreate("ImageMagickObject.MagickImage.1")
$img.Convert("test.jpg","-implode","-1","out.jpg")

Posted Image

Edited by Werty

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You could use ImageMagick...

$img = ObjCreate("ImageMagickObject.MagickImage.1")
$img.Convert("test.jpg","-implode","-1","out.jpg")

haha, awesome! Thanks, this is actually a little cool, now I'm gonna see what I can do with this.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%%scriptfile%_Obfuscated.au3"
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
HotKeySet("{ESC}","close")
Global $Img = @ScriptDir&"test.png"
Global $ImgMgc = ObjCreate("ImageMagickObject.MagickImage.1")
Global $aM_Mask, $GUI, $hwnd
Global $IMAGE_BITMAP = 0
Global $STM_SETIMAGE = 0x0172
Init()
Func Init()
_GDIPlus_Startup()
Local $hwnd = GUICreate("Test", 300, 300, -1, -1,$WS_POPUP,$WS_EX_TOPMOST,GUICreate("ghost"));
GUICtrlCreatePic("",0,0,400,400,-1,0x00100000); only for enable dragging of the gui
GUISetBkColor(0x000000,$hwnd)
_ScreenCapture_CaptureWnd($Img,$hwnd);leaving the courser...
If IsObj($ImgMgc) Then
  $ImgMgc.Convert($Img,"-implode","-1",$Img)
EndIf
GUISetState()
Local $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
Local $bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
Local $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
Local $Pos = WinGetPos($hwnd)
Local $TmpPos = $Pos
Local $image = _GDIPlus_ImageLoadFromFile($Img)
Local $matrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($matrix, 150, 150);True)
setTrans($hwnd)
Do
  $Pos = WinGetPos($hwnd)
  If ($Pos[0] <> $TmpPos[0]) Or ($Pos[1] <> $TmpPos[1]) Then
   GUISetState(@SW_HIDE)
   _GDIPlus_BitmapDispose($image)
   Sleep(100)
   _ScreenCapture_CaptureWnd($Img,$hwnd);leaving the courser..
   If IsObj($ImgMgc) Then
    $ImgMgc.Convert($Img,"-implode","-1",$Img)
   EndIf
   $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
   $bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
   $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
   $image = _GDIPlus_ImageLoadFromFile($Img)
   $matrix = _GDIPlus_MatrixCreate()
   _GDIPlus_MatrixTranslate($matrix, 150, 150);True)
   GUISetState(@SW_SHOW)
   $Pos = WinGetPos($hwnd)
   $TmpPos = $Pos
  EndIf
  ;_GDIPlus_MatrixRotate($matrix, 0.01)
  _GDIPlus_GraphicsSetTransform($backbuffer, $matrix)
  _GDIPlus_GraphicsDrawImageRect($backbuffer, $image, -150, -150, 300, 300);-150,-150)
  _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 300, 300)
  Sleep(20)
Until 0

Return
EndFunc

Func close()
    Exit
EndFunc  ;==>close
Func setTrans($hW)
Local $x, $Startx, $Endx
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)

    For $y = 0 To 300
        $x = Abs((150 * 150 - (150 - $y) * (150 - $y)) ^ 0.5)
        $Startx = 150 + $x
        $Endx = 300
        addRegion($Startx, $y, $Endx, $y)
        $Startx = 0
        $Endx = 150 - $x
        addRegion($Startx, $y, $Endx, $y)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hW, "long", $aM_Mask[0], "int", 1)
EndFunc  ;==>setTrans
Func addRegion($a, $b, $c, $d)
    Local $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $a, "long", $b, "long", $c + 1, "long", $d + 1)
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc  ;==>addRegion

Posted Image

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this:

Lens Effect:

;original code by eukalyptus (Black Hole) - modified by UEZ
#include <gdiplus.au3>
#include <guiconstantsex.au3>
#include <screencapture.au3>
#include <windowsconstants.au3>
HotKeySet("{ESC}", "_Exit")

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)

_GDIPlus_Startup()

Global $iWidth = @DesktopWidth
Global $iHeight = @DesktopHeight

Global $iSize = 150
Global $fArea = 0.70

Global $hBmp = _ScreenCapture_Capture("", -$iSize , -$iSize, $iWidth + $iSize, $iHeight + $iSize, False)
Global $hBGBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_WinAPI_DeleteObject($hBmp)

Global $hGui = GUICreate("Lens Effect", $iWidth, $iHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xABCDEF)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()
_WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF)

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
;~ DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hGfxBuffer, "int", 7)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")

;~ _WinAPI_ShowCursor(False)

Global $iOMPosX, $iOMPosY, $aMPos

While 1
    $aMPos = MouseGetPos()
    If $aMPos[0] <> $iOMPosX Or $aMPos[1] <> $iOMPosY Then
         _Draw()
         $iOMPosX = $aMPos[0]
         $iOMPosY = $aMPos[1]
    EndIf
    Sleep(30)
WEnd

Func _Draw()
    Local $aPos = MouseGetPos()
    $aPos[0] -= $iSize / 2
    $aPos[1] -= $iSize / 2
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)
    Local $hBitmap = _GDIPlus_BitmapCloneArea($hBGBitmap, $aPos[0] + $iSize, $aPos[1] + $iSize , $iSize, $iSize)

    Local $hTexture = _GDIPlus_TextureCreate($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)

    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iSize, $iSize, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    Local $fScale = 1
    Local $hMatrix = _GDIPlus_MatrixCreate()

    _GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iSize, $iSize, $hTexture)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)

    Local $fTmp = 0
    For $i = 2 To Floor($iSize / 3.333)
        $fTmp = $i * ($iSize * $fArea) / ($iSize / 2)
        $fScale = (($iSize - $fTmp) / ($iSize - $i * 2))

        _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
        _GDIPlus_MatrixTranslate($hMatrix, $iSize / 2, $iSize / 2)
        _GDIPlus_MatrixScale($hMatrix, $fScale, $fScale)
        _GDIPlus_MatrixTranslate($hMatrix, -$iSize / 2, -$iSize / 2)
        _GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
        _GDIPlus_GraphicsFillEllipse($hContext, $i, $i, $iSize - $i * 2, $iSize - $i * 2, $hTexture)
    Next

    _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
    _GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BrushDispose($hTexture)

    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBitmap, $aPos[0] - 1, $aPos[1] + 1)

    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
EndFunc   ;==>_Draw

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return True
EndFunc   ;==>WM_ERASEBKGND

Func _Exit()
    _WinAPI_ShowCursor(True)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_BitmapDispose($hBGBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func _GDIPlus_TextureCreate($hImage, $iWrapMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "ptr", $hImage, "int", $iWrapMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[3]
EndFunc   ;==>_GDIPlus_TextureCreate

Func _GDIPlus_MatrixSetElements($hMatrix, $nM11, $nM12, $nM21, $nM22, $nDX, $nDY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetMatrixElements", "hwnd", $hMatrix, "float", $nM11, "float", $nM12, "float", $nM21, "float", $nM22, "float", $nDX, "float", $nDY)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_MatrixSetElements

Lens Effect with Black Dot:

;original code by eukalyptus (Black Hole) - modified by UEZ
#include <gdip.au3>
#include <guiconstantsex.au3>
#include <screencapture.au3>
#include <windowsconstants.au3>
HotKeySet("{ESC}", "_Exit")

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)

_GDIPlus_Startup()

Global $iWidth = @DesktopWidth
Global $iHeight = @DesktopHeight

Global $iSize = 150
Global $fArea = 0.6666

Global $hBmp = _ScreenCapture_Capture("", -$iSize , -$iSize, $iWidth + $iSize, $iHeight + $iSize, False)
Global $hBGBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_WinAPI_DeleteObject($hBmp)

Global $hGui = GUICreate("Lens Effect", $iWidth, $iHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xABCDEF)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()
_WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF)

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)


Global $hBrush = _CreateBrush()

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")

;~ _WinAPI_ShowCursor(False)

Global $iOMPosX, $iOMPosY, $aMPos

While 1
    $aMPos = MouseGetPos()
    If $aMPos[0] <> $iOMPosX Or $aMPos[1] <> $iOMPosY Then
         _Draw()
         $iOMPosX = $aMPos[0]
         $iOMPosY = $aMPos[1]
    EndIf
    Sleep(50)
WEnd

Func _Draw()
    Local $aPos = MouseGetPos()
    $aPos[0] -= $iSize / 2
    $aPos[1] -= $iSize / 2
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)
    Local $hBitmap = _GDIPlus_BitmapCloneArea($hBGBitmap, $aPos[0] + $iSize, $aPos[1] + $iSize , $iSize, $iSize)

    Local $hTexture = _GDIPlus_TextureCreate($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)

    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iSize, $iSize, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    Local $fScale = 1
    Local $hMatrix = _GDIPlus_MatrixCreate()

    _GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iSize, $iSize, $hTexture)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)

    Local $fTmp = 0
    For $i = 2 To Floor($iSize / 3.333)
        $fTmp = $i * ($iSize * $fArea) / ($iSize / 2)
        $fScale = (($iSize - $fTmp) / ($iSize - $i * 2))

        _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
        _GDIPlus_MatrixTranslate($hMatrix, $iSize / 2, $iSize / 2)
        _GDIPlus_MatrixScale($hMatrix, $fScale, $fScale)
        _GDIPlus_MatrixTranslate($hMatrix, -$iSize / 2, -$iSize / 2)
        _GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
        _GDIPlus_GraphicsFillEllipse($hContext, $i, $i, $iSize - $i * 2, $iSize - $i * 2, $hTexture)
    Next

    _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
    _GDIPlus_GraphicsSetTransform($hContext, $hMatrix)

    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iSize, $iSize, $hBrush)

    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BrushDispose($hTexture)

    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBitmap, $aPos[0] - 1, $aPos[1] + 1)

    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
EndFunc   ;==>_Draw

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return True
EndFunc   ;==>WM_ERASEBKGND

Func _Exit()
    _WinAPI_ShowCursor(True)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_BitmapDispose($hBGBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func _CreateBrush()
    Local $fTmp = $iSize * 0.7
    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddEllipse($hPath, $fTmp, $fTmp, $iSize - $fTmp * 2, $iSize - $fTmp * 2)

    Local $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
    _GDIPlus_PathBrushSetCenterColor($hBrush, 0xFFF7F7F7)
    Local $aColor[2] = [1, 0x00111111]
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColor)
    _GDIPlus_PathBrushSetFocusScales($hBrush, 0.25, 0.25)
    _GDIPlus_PathBrushSetGammaCorrection($hBrush, True)
    _GDIPlus_PathDispose($hPath)

    Return $hBrush
EndFunc   ;==>_CreateBrush

It is a modification of eukalyptus' Black Hole example.

Br,

UEZ

Edit: add code to display also border instead of black ellipse

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Try this:

;original code by eukalyptus (Black Hole) - modified by UEZ
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}", "_Exit")

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)

_GDIPlus_Startup()

Global $iWidth = @DesktopWidth
Global $iHeight = @DesktopHeight

Global $iSize = 150
Global $fArea = 0.70

Global $hBmp = _ScreenCapture_Capture("", 0, 0, $iWidth - 1, $iHeight - 1, False)
Global $hBGBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_WinAPI_DeleteObject($hBmp)

Global $hGui = GUICreate("Lense Effect", $iWidth, $iHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xABCDEF)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()
_WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF)

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")

;~ _WinAPI_ShowCursor(False)

Global $iOMPosX, $iOMPosY, $aMPos

While 1
    $aMPos = MouseGetPos()
    If $aMPos[0] <> $iOMPosX Or $aMPos[1] <> $iOMPosY Then
         _Draw()
         $iOMPosX = $aMPos[0]
         $iOMPosY = $aMPos[1]
    EndIf
    Sleep(50)
WEnd

Func _Draw()
    Local $aPos = MouseGetPos()
    $aPos[0] -= $iSize / 2
    $aPos[1] -= $iSize / 2
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFFABCDEF)
    Local $hBitmap = _GDIPlus_BitmapCloneArea($hBGBitmap, $aPos[0], $aPos[1], $iSize, $iSize)

    Local $hTexture = _GDIPlus_TextureCreate($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)

    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iSize, $iSize, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    Local $fScale = 1
    Local $hMatrix = _GDIPlus_MatrixCreate()

    _GDIPlus_GraphicsFillEllipse($hContext, 0, 0, $iSize, $iSize, $hTexture)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)

    Local $fTmp = 0
    For $i = 2 To Floor($iSize / 3.333)
        $fTmp = $i * ($iSize * $fArea) / ($iSize / 2)
        $fScale = (($iSize - $fTmp) / ($iSize - $i * 2))

        _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
        _GDIPlus_MatrixTranslate($hMatrix, $iSize / 2, $iSize / 2)
        _GDIPlus_MatrixScale($hMatrix, $fScale, $fScale)
        _GDIPlus_MatrixTranslate($hMatrix, -$iSize / 2, -$iSize / 2)
        _GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
        _GDIPlus_GraphicsFillEllipse($hContext, $i, $i, $iSize - $i * 2, $iSize - $i * 2, $hTexture)
    Next

    _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0)
    _GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BrushDispose($hTexture)

    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBitmap, $aPos[0] - 1, $aPos[1] + 1)

    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
EndFunc   ;==>_Draw

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return True
EndFunc   ;==>WM_ERASEBKGND

Func _Exit()
    _WinAPI_ShowCursor(True)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_BitmapDispose($hBGBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func _GDIPlus_TextureCreate($hImage, $iWrapMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "ptr", $hImage, "int", $iWrapMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[3]
EndFunc   ;==>_GDIPlus_TextureCreate

Func _GDIPlus_MatrixSetElements($hMatrix, $nM11, $nM12, $nM21, $nM22, $nDX, $nDY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetMatrixElements", "hwnd", $hMatrix, "float", $nM11, "float", $nM12, "float", $nM21, "float", $nM22, "float", $nDX, "float", $nDY)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_MatrixSetElements

It is a modification of eukalyptus' Black Hole example.

Br,

UEZ

That's pretty cool and saved, thanks.

Also, I wanted to ask you but didn't want to PM you, so now that you're here, I wanted to know if you could help me out by adding a little dot to the center of the image created by the script so that no matter where I move it, there would always be a black circle making it look a little more authentic, I've been trying to get some code that will change the pixel color at the very center to a black color so that it will always look like the image I posted above, if it's not asking to much.

Thanks for the examples, I find most of your GDI stuff pretty entertaining!


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Have a look above (post #4).

Is this what you want?

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Have a look above (post #4).

Is this what you want?

Br,

UEZ

wow, I really appreciate that, that's what I was after, now I'm off to implement this on the original script I posted, thanks for the help UEZ! :)


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Have a look above (post #4).

Is this what you want?

Br,

UEZ

Ok, so I got back from some stuff and went back to this, and after about 3 hours... I finally got it to work, this is exactly the effect I was looking for!

#NoTrayIcon
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%%scriptfile%_Obfuscated.au3"
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Obfuscator_Ignore_Funcs=WM_DROPFILES_FUNC
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include "GDIp.au3"

HotKeySet("{ESC}", "close")

Global $Img = @DesktopDir & "test.png"
Global $ImgMgc = ObjCreate("ImageMagickObject.MagickImage.1")

If Not IsObj($ImgMgc) Then
Exit MsgBox(16, "Error", "You need to install the ImageMagic COM object.")
EndIf

Global $aM_Mask, $GUI, $hwnd
Global $IMAGE_BITMAP = 0
Global $STM_SETIMAGE = 0x0172
Global $gaDropFiles[1]

Init()

Func Init()
_GDIPlus_Startup()
Local $hwnd = GUICreate("Test", 300, 300, -1, -1, $WS_POPUP, -1, GUICreate("ghost"));$WS_EX_TOPMOST
Local $Pic = GUICtrlCreatePic("", 0, 0, 400, 400, -1, $GUI_WS_EX_PARENTDRAG); only for enable dragging of the gui
GUISetBkColor(0x000000, $hwnd)
;_ScreenCapture_CaptureWnd($Img,$hwnd);leaving the courser...
CreateImg($hwnd, $Img, 0.50)

If IsObj($ImgMgc) Then
$ImgMgc.Convert($Img, "-implode", "-15", $Img)
EndIf

GUISetState()

Local $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
Local $bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
Local $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

Local $Pos = WinGetPos($hwnd)
Local $TmpPos = $Pos

Local $image = _GDIPlus_ImageLoadFromFile($Img)
Local $matrix = _GDIPlus_MatrixCreate()

_GDIPlus_MatrixTranslate($matrix, 150, 150);True)
;_GDIPlus_MatrixRotate($matrix, 0.01)
_GDIPlus_GraphicsSetTransform($backbuffer, $matrix)
_GDIPlus_GraphicsDrawImageRect($backbuffer, $image, -150, -150, 300, 300);-150,-150)
_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 300, 300)

setTrans($hwnd)

Local $Msg, $SEC = @SEC
While 1
Sleep(20)
$Msg = GUIGetMsg($hwnd)
Switch $Msg
Case $Pic
$Pos = WinGetPos($hwnd)
If ($Pos[0] <> $TmpPos[0]) Or ($Pos[1] <> $TmpPos[1]) Then
GUISetState(@SW_HIDE)
_GDIPlus_BitmapDispose($image)
Sleep(100)
CreateImg($hwnd, $Img, 0.50)

If IsObj($ImgMgc) Then
$ImgMgc.Convert($Img, "-implode", "-18", $Img)
EndIf

$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$image = _GDIPlus_ImageLoadFromFile($Img)
$matrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($matrix, 150, 150);True)
GUISetState(@SW_SHOW)
$Pos = WinGetPos($hwnd)
$TmpPos = $Pos
EndIf

;_GDIPlus_MatrixRotate($matrix, 0.01)
_GDIPlus_GraphicsSetTransform($backbuffer, $matrix)
_GDIPlus_GraphicsDrawImageRect($backbuffer, $image, -150, -150, 300, 300);-150,-150)
_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 300, 300)
EndSwitch
If @SEC <> $SEC Then
_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 300, 300)
$SEC = @SEC
EndIf
WEnd
Return
EndFunc   ;==>Init

Func CreateImg($hGui, $ImgPath, $fArea)
If Not IsHWnd($hGui) Then
Exit MsgBox(0, "", "error")
EndIf
Local $iWidth = 300
Local $iHeight = 300
Local $iSize = 300

Local $hBmp = _ScreenCapture_CaptureWnd("", $hGui, 0, 0, $iWidth, $iHeight, False)
Local $hBGBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
Local $hBrush = _CreateBrush($iSize, $fArea)
Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBGBitmap)
_GDIPlus_GraphicsFillRect($hContext, 0, 0, $iSize, $iSize, $hBrush)

_GDIPlus_ImageSaveToFile($hBGBitmap, $ImgPath)

_WinAPI_DeleteObject($hBmp)
_GDIPlus_BitmapDispose($hBGBitmap)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_BitmapDispose($hBGBitmap)

Return $ImgPath
EndFunc   ;==>CreateImg

Func _CreateBrush($iSize, $fArea)
Local $fTmp = $iSize * $fArea * 1.20
Local $hPath = _GDIPlus_PathCreate()
;_GDIPlus_PathAddEllipse($hPath, $fTmp, $fTmp, $iSize - $fTmp * 2, $iSize - $fTmp * 2)
_GDIPlus_PathAddEllipse($hPath, $fTmp - 25, $fTmp - 25, -10, -10)

Local $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath)
_GDIPlus_PathBrushSetCenterColor($hBrush, 0xFF000000)
Local $aColor[2] = [1, 0x00000000]
_GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColor)
_GDIPlus_PathBrushSetFocusScales($hBrush, 0.5, 0.5)
_GDIPlus_PathBrushSetGammaCorrection($hBrush, True)
_GDIPlus_PathDispose($hPath)

Return $hBrush
EndFunc   ;==>_CreateBrush

Func close()
_GDIPlus_Shutdown()
Exit
EndFunc   ;==>close


Func setTrans($hW)
Local $x, $Startx, $Endx
$aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)


For $y = 0 To 300
$x = Abs((150 * 150 - (150 - $y) * (150 - $y)) ^ 0.5)
$Startx = 150 + $x
$Endx = 300
addRegion($Startx, $y, $Endx, $y)
$Startx = 0
$Endx = 150 - $x
addRegion($Startx, $y, $Endx, $y)
Next

DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hW, "long", $aM_Mask[0], "int", 1)
EndFunc   ;==>setTrans

Func addRegion($a, $b, $c, $d)
Local $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $a, "long", $b, "long", $c + 1, "long", $d + 1)
DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc   ;==>addRegion

Also, I wonder why the tab spaces always disappear when I post code...

Edited by THAT1ANONYMOUSEDUDE

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • SimTheNo1
      By SimTheNo1
      I am busy with building a solution for change monitoring of VOIP call program and to be properly automated means among others need for some limited OCR functionality. Current works of others are way too much overkill for this case what makes the need to build it myself. But to do it properly I significantly have to increase my knowledge about digital graphics management.
      For now I already have discovered here and there some mind blowing  Autoit miracles what can be achieved with Windows own possibilities to manipulate that what is output to the monitor. And as far I can judge there are 2 options to process graphics without use of any external libraries like ImageMagick, FreeImage and so on. These are:
       WinAPI  GDIPlus It is for me quite obvious to have various holes in general understanding of graphics and it is once more very clear what advantages gives consistent general study in 1 or another official institutions like University.  Cause there you are introduced into certain domain of knowledge in a way which usually has been perfected over long period of time. So you are not overloaded by stuff which requires a certain amount of information to be initially clear for you. For example, before starting to solve physics you first learn to read, count and so on and then move to subjects like physics.
      Though in my case opportunity to study in such educational system I had only for 8 years, from my 7th to 15th year of age in the country that was falling apart now Ukraine but used to be USSR, was all what it was. After have immigrated to Netherlands possibilities to study further haven't occur. And this therefor causes often various implications when going deep in that or another field of practical knowledge acquiring for any needed physical result, like programming to perform enormous amount of tasks. In this particular case automating VOIP call program.
      Anyway, right now I think the best direction to move is to concentrate on as basic as possible image management and if someone would maybe explain in general what is a pixel will definitely help. Particularly I am very curious about how to do picture manipulations in Autoit. Especially would help a lot to produce eventually following functions:
      createImage($imageFileName, $width, $height, $color) readImagePixel($imageFileName, $x, $y)  writeImagePixel($imageFileName, $x, $y) I do not know exactly how image is handled in computer but preferably above mentioned functions should deal with so far possible origin of graphics creation on computer. But nevertheless I definitely would love to hear any proposition for solution.
      The problem with explaining screenshots:
       VOIPConnect full Window  Part of Window with control to monitor for changes  Exact location of area where actual changes occur and have to be processed  It comes down to a rectangle of approximately 51 pixel wide and 7 pixel high. In fact if I get to learn as far as to be able exactly read, write and compare 2 images consistently across different computers I could narrow down then even further the area to watch as little as a square of 2-5 pixels wide. 
      To finish here is last detail about particularly no need for ultra fast solution at all. This because it is needed only once when it is first run on a new computer and to have to wait few minutes while it is being set instead of just a few seconds make no sence.
      This is it and what I too think to do beside this very particular case is to purify out beautiful generic Autoit functions for core image manipulation by using WinAPI or/and GDIPlus. 
    • Ian_Mac
      By Ian_Mac
      Func dg_get_images() $x1=0 $y1=0 ;MsgBox(0,"start","start") do $result = _ImageSearch("C:\Users\Server\Desktop\my project\image.png",1,$x1,$y1,0) until $result = 1; if $result=1 Then MouseMove($x1,$y1,3) MouseClick("left", $x1,$y1, 1) WinWait("[Title:TightVNC File Transfer]", "", 10) EndIf  this code works when i search the image, but when i change the location of the desktop icon it can't find the desktop icon anymore.   i wanna try image search area. but i don't know how to use it because i cant understand the parameter for the image search area.  please help me how to solve it thank you in advance.
    • rootx
      By rootx
      I would like to download the first 5 images in a folder. THX.
      #include <INet.au3> #include <String.au3> #include <Array.au3> Global $sSource, $aImgURL, $sKeyWord $sKeyWord = "pug" $sSource = _INetGetSource("http://www.google.com/search?q=" & $sKeyWord & "&tbm=isch") $aImgURL = _StringBetween($sSource, 'src="', '"') For $x = 1 to UBound($aImgURL)-1 ConsoleWrite($aImgURL[$x]&@CRLF) Next  
    • nbg15
      By nbg15
      Hello everybody..
       
      i have this picture here *attached* and this script here: 
       
      $ImageToReadPath = @MyDocumentsDir & "\GDIPlus_Image2.jpg" $ResultTextPath = @MyDocumentsDir & "\Result" $OutPutPath = $ResultTextPath & ".txt" $TesseractExePath = @MyDocumentsDir & "\Tesseract.exe" ShellExecuteWait($TesseractExePath, '"' & $ImageToReadPath & '" "' & $ResultTextPath & '"', "", "", @SW_HIDE) If @error Then Exit MsgBox(0, "Error", @error) EndIf MsgBox(0, "Result", FileRead($OutPutPath)) FileDelete($OutPutPath)  
      but tesseract doesnt recognized the correct word... and gives me trash back...

      this is the image >> 
      and the result was >> "samm" 

      the image was an normal jpg and generated with this code here:
       
      _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image2.jpg", 712,268,853,284)
      Could anybody give me a hint what i can do better to get this easy image to text?
       
      thank u very much!!!
       
       
      Edit: i also tried to capture the screen as bmp with a higher resolution... nothing changed... 
       
       
      _ScreenCapture_SetBMPFormat(4) _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.bmp", 712,279,853,295)  
    • RyukShini
      By RyukShini
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=car.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> ; Declare array Dim $Images[1] ; Gets all JPG files in the current directory (@ScriptDir). Local $search = FileFindFirstFile("*.jpg") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No JPG files could be found.") Exit EndIf ; Resize array While 1 If IsArray($Images) Then Local $Bound = UBound($Images) ReDim $Images[$Bound+1] EndIf $Images[$Bound] = FileFindNextFile($search) If @error Then ExitLoop WEnd ; Close the search handle FileClose($search) ; Create directory "resized" if not there yet $nymappe = InputBox("Mappe / Bil Navn", "Mappe / Bil Navn") If NOT FileExists(@ScriptDir & "\" & $nymappe & "\") Then DirCreate(@ScriptDir & "\" & $nymappe & "\") EndIf ; Loop for JPGs - gets dimension of JPG and calls resize function to resize to 50% width and 50% height For $i = 1 to Ubound($Images)-1 If $Images[$i] <> "" AND FileExists(@ScriptDir & "\" & $Images[$i]) Then Local $ImagePath = @ScriptDir & "\" & $Images[$i] _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($ImagePath) Local $ImageWidth = _GDIPlus_ImageGetWidth($hImage) Local $ImageHeight = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ;MsgBox(0,"DEBUG", $ImageWidth & " x " & $ImageHeight) Local $NewImageWidth = ($ImageWidth / 100) * 15 Local $NewImageHeight = ($ImageHeight / 100) * 15 ;MsgBox(0,"DEBUG: " & $i,$Images[$i]) _ImageResize(@ScriptDir & "\" & $Images[$i], @ScriptDir & "\" & $nymappe & "\" & $Images[$i], $NewImageWidth, $NewImageHeight) EndIf Next ; Resize function Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 ;OutFile path, to use later on. Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) ;OutFile name, to use later on. Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1) ;OutFile extension , to use for the encoder later on. Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) ; Win api to create blank bitmap at the width and height to put your resized image on. $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDC) ;Start GDIPlus _GDIPlus_Startup() ;Get the handle of blank bitmap you created above as an image $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) ;Load the image you want to resize. $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) ;Get the graphic context of the blank bitmap $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1) ;Draw the loaded image onto the blank bitmap at the size you want _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH) ;Get the encoder of to save the resized image in the format you want. $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image. Do $i += 1 Until (Not FileExists($sOP & $i & "_" & $sOF)) ;Prefix the number to the begining of the output filename $sOutImage = $sOP & $i & "_" & $sOF ;Save the new resized image. _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc Quality gets quite bad compared to using Paint / Photoshop when resizing with GDIPlus
      Any idea how to make the quality better?
      Thanks in advance