Jump to content

Recommended Posts

Posted

looks like you are making a photo editor. not bad! :)

It could use some work, but I think you are getting close. be sure to take a look at the reverse button.

Good luck withit.

Posted

here ya go

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "_Custom_Exit")
$GUI = GUICreate("Unimportant GUI", @DesktopWidth, @DesktopHeight, Default, Default, $WS_POPUPWINDOW)

$oImage = ObjCreate("WIA.ImageFile")
$s_Path = FileOpenDialog("Select Gif Image", @ScriptDir, "Gif Images (*.jpg)")
$oImage.LoadFile ($s_Path)
$HorizontalRes = $oImage.Width
$VerticalRes = $oImage.Height

If $oImage.Width > @DesktopWidth Or $oImage.Height > @DesktopHeight Then
    If $oImage.Width > @DesktopWidth And $oImage.Height > @DesktopHeight And $oImage.Width <> $oImage.Height Then
        If $oImage.Width > $oImage.Height Then
            $HorizontalRes = @DesktopWidth
            $HorizontalResPerc = (1 - (($oImage.Width - @DesktopWidth) / $oImage.Width))
            $VerticalRes = $oImage.Height * ($HorizontalResPerc)
        Else
            $VerticalRes = @DesktopHeight
            $VerticalResPerc = (1 - (($oImage.Height - @DesktopHeight) / $oImage.Height))
            $HorizontalRes = $oImage.Width * ($VerticalResPerc)
        EndIf
    EndIf

Else

    If $oImage.Width > @DesktopWidth Then
        $HorizontalRes = @DesktopWidth
        $HorizontalResPerc = (1 - (($oImage.Width - @DesktopWidth) / $oImage.Width))
        $VerticalRes = $oImage.Height * ($HorizontalResPerc)
    ElseIf $oImage.Height > @DesktopHeight Then
        $VerticalRes = @DesktopHeight
        $VerticalResPerc = (1 - (($oImage.Height - @DesktopHeight) / $oImage.Height))
        $HorizontalRes = $oImage.Width * ($VerticalResPerc)
    EndIf
EndIf

;GUICtrlCreatePic ( filename, left, top [, width [, height [, style [, exStyle]]]] )
$Pic = GUICtrlCreatePic($s_Path, Default, Default, $HorizontalRes, $VerticalRes)
GUISetState(@SW_SHOW, $GUI)

; ============================================================================
; Main Loop
; ============================================================================

While 1
    Sleep(10)
WEnd

; ============================================================================
; Functions
; ============================================================================
Func _Custom_Exit()
    Exit
EndFunc   ;==>_Custom_Exit
Posted

Hello,

here is an example for scaling.

Just drag an image to the window, it will be shown in original size first.

After a short pause, the image will be scaled to the windows dimension.

Same happens at maximize and resize.

The scaling is in func getScaled().

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

$gWin = GUICreate('imgt',400,300,-1,-1,BitOR($WS_OVERLAPPEDWINDOW,$WS_CLIPSIBLINGS,$WS_SYSMENU),$WS_EX_ACCEPTFILES)
GUICtrlCreateLabel('',0,0,400,300)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
$gImg = GUICtrlCreatePic(@ProgramFilesDir & '\Messenger\lvback.gif',0,0,0,0)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
GUISetState()

While 1
    Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_DROPPED
            setNewImg(@GUI_DragFile)
        Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            resizeImg($gImg)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func setNewImg($sImgPath)
    GUICtrlDelete($gImg)
    $gImg = GUICtrlCreatePic($sImgPath,0,0,0,0)
    GUICtrlSetState(-1,$GUI_ACCEPTFILES)
    ToolTip('original size')
    sleep(800)
    resizeImg($gImg)
    ToolTip('scaled size')
    sleep(800)
    ToolTip('')
EndFunc

Func resizeImg($ctrl)
    Local $aImgPos = ControlGetPos('imgt','',$ctrl)
    Local $aWinPos = WinGetClientSize('imgt')
    Local $aPos = getScaled($aImgPos[2],$aImgPos[3],$aWinPos[0],$aWinPos[1])
    GUICtrlSetPos($ctrl,0,0,$aPos[0],$aPos[1])
EndFunc

Func getScaled($iWidth,$iHeight,$xMax,$yMax)
    If $xMax/$iWidth > $yMax/$iHeight Then
        Local $a[2] = [($yMax/$iHeight)*$iWidth,$yMax]
        Return $a
    Else
        Local $a[2] = [$xMax,($xMax/$iWidth)*$iHeight]
        Return $a
    EndIf
EndFunc

ciao

Xandl

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
×
×
  • Create New...