Jump to content

GDI plus zoom in zoom out and rotate problem


Recommended Posts

Hello everyone, I have problems in understanding the GDI I think I did well but it does not rotate the photo, or rather I would like to rotate the photo from the center or instead the rotate from the left corner, and even when I zoom it starts with a very small photo and then it goes out size, why ?

this is my code  

#include <GuiconstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GDIPlus.au3>
#include <WinAPIHObj.au3>

Global Const $SC_DRAGMOVE = 0xF012, $iGStepZoom = 5
Global $a = 255, $z = 0

HotKeySet("{ESC}", "On_Exit")
Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Global $hGUI = GUICreate("X", 943, 718, -1, -1, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
;$Pic1 = GUICtrlCreatePic("C:\patOK.bmp", 25, -1, 950, 750)
$Button1 = GUICtrlCreateButton("\", 0, 0, 27, 25)
$Button2 = GUICtrlCreateButton("↓", 0, 23, 27, 25)
$Button3 = GUICtrlCreateButton("→", 0, 46, 27, 25)
$Checkbox1 = GUICtrlCreateCheckbox("inv", 0, 70, 33, 17)
$Button4 = GUICtrlCreateButton("A+", 0, 93, 27, 25)
$Button5 = GUICtrlCreateButton("A-", 0, 116, 27, 25)
$Button6 = GUICtrlCreateButton("Zi+", 0, 139, 27, 25)
$Button7 = GUICtrlCreateButton("Zi-", 0, 162, 27, 25)
$Button8 = GUICtrlCreateButton("R►", 0, 185, 27, 25)

GUISetState(@SW_SHOW)

_GDIPlus_Startup()
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsClear($hGraphics)

; Take Screenshot at bottom left of screen
Local $hScreenCap_hBitmap = "C:\patOK.bmp"
$iW = _GDIPlus_ImageGetWidth($hScreenCap_hBitmap)
$iH = _GDIPlus_ImageGetHeight($hScreenCap_hBitmap)
$iW2 = $iW / 2
$iH2 = $iH / 2
Local $hScreenCap_Bitmap = _GDIPlus_BitmapCreateFromFile($hScreenCap_hBitmap)

Local $hMatrix = _GDIPlus_MatrixCreate()
; Scale the matrix by 2 (everything will get 2x larger)
;_GDIPlus_MatrixScale($hMatrix, 2.0, 2.0)

_GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hScreenCap_Bitmap, 25, -1, 950, 750)




While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
        Case $Button1
            $WGP = WinGetPos($hGUI)
            If (GUICtrlRead($Checkbox1) = 1) Then
                WinMove($hGUI, "", Default, Default, $WGP[2] - $iGStepZoom, $WGP[3] - $iGStepZoom)
            Else
                WinMove($hGUI, "", Default, Default, $WGP[2] + $iGStepZoom, $WGP[3] + $iGStepZoom)
            EndIf
        Case $Button2
            $WGP = WinGetPos($hGUI)
            If (GUICtrlRead($Checkbox1) = 1) Then
                WinMove($hGUI, "", Default, Default, Default, $WGP[3] - $iGStepZoom)
            Else
                WinMove($hGUI, "", Default, Default, Default, $WGP[3] + $iGStepZoom)
            EndIf
        Case $Button3
            $WGP = WinGetPos($hGUI)
            If (GUICtrlRead($Checkbox1) = 1) Then
                WinMove($hGUI, "", Default, Default, $WGP[2] - $iGStepZoom, Default)
            Else
                WinMove($hGUI, "", Default, Default, $WGP[2] + $iGStepZoom, Default)
            EndIf

        Case $Button4 ; alpha +
            $a += 20
            If $a < 255 Then
                WinSetTrans($hGUI, "", $a)
            EndIf
        Case $Button5  ; alpha -
            $a -= 20
            If $a > 0 Then
                WinSetTrans($hGUI, "", $a)
            EndIf
        Case $Button6   ; zoom in image
            $z += 0.5
            _GDIPlus_MatrixScale($hMatrix, $z, $z)
            _GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix)
            _GDIPlus_GraphicsDrawImageRect($hGraphics, $hScreenCap_Bitmap, 25, -1, 950, 750)
        Case $Button7 ; zoom out image
            $z -= 0.5
            _GDIPlus_MatrixScale($hMatrix, $z, $z)
            _GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix)
            _GDIPlus_GraphicsDrawImageRect($hGraphics, $hScreenCap_Bitmap, 25, -1, 950, 750)
        Case $Button8 ; rotation right
            _GDIPlus_MatrixTranslate($hMatrix, $iW2, $iW2) ; move it back to 0, 0 since (112 / 2) and (37 / 2) are it's middle origin point
            _GDIPlus_MatrixRotate($hMatrix, 1) ; rotate it around it's middle origin point
            _GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix)
            _GDIPlus_GraphicsDrawImage($hGraphics, $hScreenCap_Bitmap, 25, 90)

    EndSwitch
WEnd


; Clean up resources
_WinAPI_DeleteObject($hScreenCap_hBitmap)
_GDIPlus_BitmapDispose($hScreenCap_Bitmap)
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()

 

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...