Jump to content

Need help resizing picture GDI+


Recommended Posts

Hi,

i found this rather old thread and the code below is based on the code by  UEZ from this thread.

The code works as expected (maybe there is a newer way to do this?), but i would like the code to resize the pictures to @DesktopWidth/@DesktopHeight

I played with

DllStructSetData($tSize, "X", @DesktopWidth)
DllStructSetData($tSize, "Y", @DesktopHeight)

but this does not work.

Can anyone show me a way to do this?

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

_GDIPlus_Startup()

local $aImages[2]
$aImages[0] = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\Web\Screen\img100.jpg")
$aImages[1] = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\Web\Screen\img102.jpg")

$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetState()
HotKeySet("{ESC}", "_Exit")

While 1
    UpdateLayeredWindow($aImages[0], $hGUI, 1, 2, 0, 0, true)
    Sleep(1000)
    UpdateLayeredWindow($aImages[0], $hGUI, 0, 2, 0, 0, true)
    UpdateLayeredWindow($aImages[1], $hGUI, 1, 2, 0, 0, true)
    Sleep(1000)
    UpdateLayeredWindow($aImages[1], $hGUI, 0, 2, 0, 0, true)
WEnd

Func _Exit()
    GUIDelete()
    _GDIPlus_ImageDispose($aImages[0])
    _GDIPlus_ImageDispose($aImages[1])
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func UpdateLayeredWindow($hBitmap, $hGUI, $iFadeDir = 2, $iStep = 2, $iX = 0, $iY = 0, $bCenter = True)
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    Local Const $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
    Local Const $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    If $bCenter Then
        $iX = (@DesktopWidth - $iWidth) / 2
        $iY = (@DesktopHeight - $iHeight) / 2
    EndIf
    WinMove($hGUI, "", $iX, $iY)
    Local Const $hScrDC = _WinAPI_GetDC($hGUI)
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    Local Const $tSize = DllStructCreate($tagSIZE)
    DllStructSetData($tSize, "X", $iWidth)
    DllStructSetData($tSize, "Y", $iHeight)
    Local Const $tSource = DllStructCreate($tagPOINT)
    Local Const $tBlend = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($tBlend, "Format", 1)
    Local $i, $hDLL = DllOpen("user32.dll")
    Switch $iFadeDir
        Case 0
            For $i = 0xFF To 0 Step -$iStep
                DllStructSetData($tBlend, "Alpha", $i)
                DllCall($hDLL, "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA)
                Sleep(10)
            Next
        Case 1
            For $i = 0 To 0xFF Step $iStep
                DllStructSetData($tBlend, "Alpha", $i)
                DllCall($hDLL, "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA)
                Sleep(10)
            Next
        Case 2
            DllStructSetData($tBlend, "Alpha", 0xFF)
            DllCall($hDLL, "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA)
    EndSwitch
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_DeleteObject($hHBitmap)
    _WinAPI_DeleteDC($hMemDC)
    DllClose($hDLL)
EndFunc   ;==>UpdateLayeredWindow

 

Link to comment
Share on other sites

You need to resize the image just after loading it and pass it afterwards to UpdateLayeredWindow function accordingly.

 

local $aImages[2][2]
$aImages[0][0] = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\Web\Screen\img100.jpg")
$aImages[0][1] = _GDIPlus_ImageResize($aImages[0][0], @DesktopWidth, @DesktopHeight)
$aImages[1][0] = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\Web\Screen\img102.jpg")
$aImages[1][1] = _GDIPlus_ImageResize($aImages[1][0], @DesktopWidth, @DesktopHeight)
...
UpdateLayeredWindow($aImages[0][1], $hGUI, 1, 2, 0, 0, true)
...

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thank you very much!

My first Picture ScreenSaver now works fine, even the preview now works as expected.

May i ask one more question:

I would like to load a background picture (the way i do it above) an the add some text and maybe a foreground picture and fade all if this this in and out.

Is this possible?

Link to comment
Share on other sites

@ESPUserif you want to watermark an image you can have a look here:

Maybe you can grab some functions for your needs. :)

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks, will take a look at the code, but the license seems to limit its usage

>You are not allowed to sell this code or use it or just parts of it in a commercial project

My ScreenSaver will be installed on my customer PCs and this may be seen as "commercial project" or "selling ".

Maybe i better start fresh 🙂

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...