Jump to content
Sign in to follow this  
Skitty

Gravitational lensing effect on image?

Recommended Posts

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

Share this post


Link to post
Share on other sites

You could use ImageMagick...

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

Posted Image

Edited by Werty

Some guy's script + some other guy's script = my script!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

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! :)

Share this post


Link to post
Share on other sites

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Gowrisankar
      Dear members of the forum,
      I'm working on a project in which I have to use Image recognition technique. 
      Due to client restrictions, I couldn't use AutoIt for this project. 
      Is there a way to use this DLL "ImageSearchDLL.dll" (which is used to do image recognition steps in AutoIt) in VB.Net to achieve the same result? 
      I have used this DLL few years before and got good results. If there is a latest version of this DLL and if you can share it, that will be helpful too.
      Any guidance is deeply appreciated.
    • By amosrinat
      Hi,
      i have an AutoIT script that sends emails with two embedded images.
      When users get the email they don't see the images. How should I fix my code?
      Thank you for your support,
      Amos
      Func fSendMail() $TemplateName = StringRegExpReplace($Template, "^.*\\|\..*$", "") $SmtpServer = "smtp.**.com" $FromName = "do-not-reply@*********" $FromAddress = "do-not-reply@******" $ToAddress = $MG1_Mgr & ";"& $Owner $Subject = "ACTION REQUIRED - " & $TemplateName $Body = $sBody5 $IPPort = 25 $ssl = 0 Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = fINetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $IPPort, $ssl) If @error Then MyErrFunc() EndIf EndFunc;fSendMail Func fINetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $IPPort = 25, $ssl = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort $objEmail.Configuration.Fields.Update $objEmail.Fields.Update ;$objEmail.Send **************** If @error Then MyErrFunc() EndIf $objEmail = "" EndFunc;fINetSmtpMailCom  
    • By coronatuss
      Hello everyone,
      Im developing an script to check the size of all .jpg stored in windows folder.
      The problem is that it doesn´t work properly with rotated images. 
      With _GDIPlus_ImageGetWidth() and _GDIPlus_ImageGetHeight()  I get the Width and Height of images as if they had not been rotated, and I need to know how they are rotated (orientation and grades).
      Any help is welcome! If more info is needed, please tell. 😁
    • By nacerbaaziz
      hello autoit team
      please i've a question for you.
      am creating a audio player
      and in this audio player i want to show the current trac info
      such as the total time and the position ... etc
      i know i can show it as label
      but the screen reader for the blind read the text every change
      because it have a screen scan
      what i want is to show this informations but such image or icon
      i mean i need to create
      GUICtrlCreatepic or GUICtrlCreateicon ....
      or some thing as that
      and show this informations as image on it
      i think that i can do that with the 
      _GDIPlus functions
      but i couldn't find the currect way to do it
      i tried the _GDIPlus_GraphicsDrawString
      but i couldn't know how it work
      what i need is a small example that create a GUI
      and add a multy line text to it as graphic or image.
      so i need a simple way because it will changed every sec
      i hope any one can help me to do that
      global $GUI = GUICreate("text", 400, 400) global $label = GUICtrlCreateLabel(GetText(), 10, 10, 380, 380) GUISetState() do sleep(100) until GUIGetMSG() = -3 exit func GetText() return StringFormat("file name is test.mp3 \r\n total time is 00:30:00 \r\n position is 00:05:50") endFunc  
    • By therks
      So I don't have any code cooked up yet as this is still in the theoretical stage. Just looking for some advice.
      My current idea is to resize the image to 1x1 pixel, probably using _GDIPlus_ImageResize, and read the color of the resulting pixel to obtain an admittedly very general sense of brightness. Does anyone think this could work?
      We have a CCTV system running at home using some home made cameras (raspberry pi) and we're trying to automate toggling settings for day/night time. We started with an AutoIt script that checked sunrise and sundown times for our location (calculations pulled from here) and toggled the settings based on that. Unfortunately our weather varies wildly, so it can get light/dark far outside normal sunrise/sundown times. Now we're hoping to periodically grab a still from the camera and toggle the light mode based on that.
×
×
  • Create New...