Page 1 sur 1
[R] Afficher une image en trapèze
Posté : mer. 25 juil. 2012 11:51
par TT22
Bonjour à tous !
Voici ma question : Est-il possible d'afficher une image en trapèze dans une GUI ?
Par exemple, j'ai cette image :

- Avatar.png (14.79 Kio) Vu 3196 fois
Je voudrais qu'elle s'affiche de cette façon dans la GUI :

- Avatar.png (16.06 Kio) Vu 3196 fois
Et évidemment qu'il soit possible de choisir le niveau de déformation
Voilà, merci d'avance à ceux qui me répondrons

Re: [..] Afficher une image en trapèze
Posté : mer. 25 juil. 2012 13:35
par timmalos
Re: [..] Afficher une image en trapèze
Posté : mer. 25 juil. 2012 18:04
par TT22
Heu, ça permet de faire pivoter des images, mais est-ce qu'on peut les déformer en trapèze ?
Re: [..] Afficher une image en trapèze
Posté : jeu. 26 juil. 2012 14:04
par sylvanie
j'arrive à un truc assez brouillon, mais si ça te permet d'avancer :
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
_Main()
Func _Main()
Local $hGUI, $hGraphic, $aPoints[5][2]
; Create GUI
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
; Draw a polygon
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(200, 200,$hGraphic); précisement, alors je me contente de les utilisé comme je vois dans
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; les scripts de pros!
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) ; ca, c'est pour l'anti-aliasing
$aPoints[0][0] = 4
$aPoints[1][0] = 150
$aPoints[1][1] = 150
$aPoints[2][0] = 350
$aPoints[2][1] = 175
$aPoints[3][0] = 350
$aPoints[3][1] = 225
$aPoints[4][0] = 150
$aPoints[4][1] = 250
_GDIPlus_GraphicsDrawPolygon($hGraphic, $aPoints)
$hImg = _GDIPlus_ImageLoadFromFile("tortue.gif")
$step=1
For $ind= 0 to 200 step $step
_GDIPlus_GraphicsDrawImage($hBuffer, $hImg, -$ind, 0)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, $ind,0,$step,200,$ind,$ind/2,$step,100-$ind/4 )
Next
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
Laisse tomber le trapèze en noire, il sert à rien
En gros la philosophie, c'est de construire plein de petit rectangle les un derrière les autres pour former un trapèze et de remplir chacun d'eux avec un découpage de l'image ( _GDIPlus_GraphicsDrawImage($hBuffer, $hImg, -$ind, 0) )
c'est pas génial mais si ça peut aider ...
Re: [..] Afficher une image en trapèze
Posté : jeu. 26 juil. 2012 15:38
par silvere
Tu ne pourrais pas reprendre la 2ème image et de jouer avec la transparance ?
Enfin a part si se n'est pas toi qui défini l'image.
Re: [..] Afficher une image en trapèze
Posté : jeu. 26 juil. 2012 16:52
par sylvanie
Bon, je l'ai nettoyé en enlevant le superflu et en le mettant un peu plus en forme de trapeze.
Et je l'ai adapté à l'avater
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
_Main()
Func _Main()
; Create GUI
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
; Draw a polygon
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(100, 100,$hGraphic); précisement, alors je me contente de les utilisé comme je vois dans
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; les scripts de pros!
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) ; ca, c'est pour l'anti-aliasing
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$step=1
For $ind= 0 to 100 step $step
_GDIPlus_GraphicsDrawImage($hBuffer, $hImg, -$ind, 0)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, $ind,0,$step,100,100+$ind,50+$ind/5,$step,100-2*$ind/5 )
Next
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
Re: [..] Afficher une image en trapèze
Posté : jeu. 26 juil. 2012 18:41
par mikell
sylvanie les proportions sont étranges avec ton script
C'est mieux comme ça mais c'est pas bufferisé
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("file.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
En tout cas ton idée est super bien trouvée (les autres solutions possibles sont des *grosses* prises de tête) et je me mets le script de côté derechef

Re: [..] Afficher une image en trapèze
Posté : jeu. 26 juil. 2012 21:13
par sylvanie
c'est clair que je n'ai pas cherché vraiment l’harmonie
ce qui me gène plus, c'est que dans mon cas, l'image disparaît en cas de réduction au switch de fenêtre ... ça reste du balbutiement ...
[EDIT]
en reprenant l'adaptation de Mikell :
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
EndFunc
On s'enregistre à l'évènement WM_PAINT pour retracer le dessin en cas de switch, mais ça ne marche pas pour la réduction ... A suivre
[RE-EDIT]
Et bah voilà
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
GUISetState()
Do
$msg=GUIGetMsg()
If $msg = $GUI_EVENT_RESTORE Then MY_WM_PAINT()
Sleep(100)
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
Return
EndFunc
Mais ce n'est pas encore très élégant ...
Re: [..] Afficher une image en trapèze
Posté : ven. 27 juil. 2012 12:09
par TT22
silvere a écrit :Enfin a part si se n'est pas toi qui défini l'image.
Ben oui, c'était ça mon problème
@ sylvanie et mikell : Merci à vous deux ça fonctionne parfaitement
PS : Essayez ça :
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
GUISetState()
Do
$msg=GUIGetMsg()
If $msg = $GUI_EVENT_RESTORE Then MY_WM_PAINT()
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/0.8, 1, $h-2*$i/0.8 )
Next
Return
EndFunc
Re: [R] Afficher une image en trapèze
Posté : ven. 27 juil. 2012 17:35
par sylvanie
Oui, j'avais remarqué aussi qu'on pouvait inverser l'affichage.
De même dans les trucs assez marrant, c'est de jouer avec la valeur du pas de boucle afin d'exagérer le côté "Rectangle":
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("GDI+", 400, 300)
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("avatar.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
GUISetState()
Do
$msg=GUIGetMsg()
If $msg = $GUI_EVENT_RESTORE Then MY_WM_PAINT()
Until $msg = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
Local $step=5
For $i = 0 to $w step $step
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, $step, $h, _
$x+$i, $y+$i/0.8, $step, $h-2*$i/0.8 )
Next
Return
EndFunc
Mais bon là on s'écarte

Re: [R] Afficher une image en trapèze
Posté : ven. 27 juil. 2012 21:54
par mikell
Hum pour maintenir l'image, c'est ça
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hImg = _GDIPlus_ImageLoadFromFile("file.png")
$w = _GDIPlus_ImageGetWidth($hImg)
$h = _GDIPlus_ImageGetHeight($hImg)
$x = 100
$y = 80
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
MY_WM_PAINT()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImg)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Func MY_WM_PAINT()
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
For $i = 0 to $w step 0.5
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImg, _
$i, 0, 1, $h, _
$x+$i, $y+$i/8, 1, $h-2*$i/8 )
Next
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc
@sylvanie
On est des bourrins, la solution était dans l'aide à GUICtrlCreatePic

Re: [R] Afficher une image en trapèze
Posté : sam. 28 juil. 2012 23:16
par sylvanie
mikell a écrit :
On est des bourrins, la solution était dans l'aide à GUICtrlCreatePic

ouaiiis
Ceci dit c'est courant chez les nains
