Page 1 sur 1

[R] Comment retailler proprement des images ?

Posté : sam. 18 avr. 2009 19:41
par papami
bonjour

soit une collection d'images de tailles diverses que je cherche à afficher sous forme de galerie ou catalogue, en respectant leurs proportions.

GUICtrlCreatePic(filename, left, top ,0,0) respecte les dimensions d'origine, mais si l'on veut donner un maximun à l'une des dimensions l'autre n'est pas mise à l'échelle pour autant.

Existe t-il alors une fonction permettant de récupérer les dimensions d'une image pour calculer la mise à l'échelle ?

merci

Re: [..] Comment retailler proprement des images ?

Posté : sam. 18 avr. 2009 21:51
par Yogui
vous pouvez vous inspirer de ce que j'ai fait :

http://www.autoitscript.fr/forum/viewto ... f=6&t=1900

Re: [..] Comment retailler proprement des images ?

Posté : dim. 19 avr. 2009 12:22
par Voodoo
En faisant une fonction avec sa :

Code : Tout sélectionner

#include <GDIPlus.au3>
#include <WinAPI.au3>
_GDIPlus_Startup ()

$hImage = _GDIPlus_ImageLoadFromFile("img.jpg")

$iX = _GDIPlus_ImageGetWidth ($hImage)
$iY = _GDIPlus_ImageGetHeight ($hImage)
msgbox(0,"Taille :",$iX & "x" & $iY)


_GDIPlus_ImageDispose ($hImage)


_GDIPlus_ShutDown ()

Re: [..] Comment retailler proprement des images ?

Posté : dim. 19 avr. 2009 16:04
par papami
OK, vu ...

Merci à vous deux.

Re: [R] Comment retailler proprement des images ?

Posté : dim. 19 avr. 2009 16:59
par GaRydelaMer
Bonjour

dans le cadre d'un de mes projet, j'affiche une série d'image dans une ListView, avec un contrôle ImageList.

j'ai créer une fonction qui les affiches en les redimensionnant et en conservant leur proportions.
_GDIPlusImageList_AddBitmap($hListImage, $Image, $w, $h)

$hListImage : le Handler du controle ImageList.
$Image : le chemin de l'image.
$w, $h, les dimension finale souhaiter

La fonction te retourne l'index de l'image dans le contrôle ImageList.
Nécessite d'inclure GDIplus, WinAPI, et Math.

Code : Tout sélectionner

Func _GDIPlusImageList_AddBitmap($hListImage, $Image, $w, $h)
    Local $_hImage = _GDIPlus_ImageLoadFromFile($Image)
    Local $_iw = _GDIPlus_ImageGetWidth($_hImage)
    Local $_ih = _GDIPlus_ImageGetHeight($_hImage)
    Local $_hDW = _WinAPI_GetDesktopWindow()
    Local $_hDC = _WinAPI_GetDC($_hDW)
    Local $__hGraphic = _GDIPlus_GraphicsCreateFromHDC($_hDC)
    _WinAPI_ReleaseDC($_hDW, $_hDC)
    Local $_hBmp = _GDIPlus_BitmapCreateFromGraphics($w, $h, $__hGraphic)
    Local $_hGraphic = _GDIPlus_ImageGetGraphicsContext($_hBmp)
    Local $_nx, $_ny, $_nw, $_nh
    ;; Effect resize and fit image
    Local $_ZoomRatio = _Min($w / $_iw, $h / $_ih)
    If $_iw * $_ZoomRatio = $w Then
        $_nw = $w
        $_nx = 0
        $_nh = $_ih * $_ZoomRatio
        $_ny = ($h - $_nh) / 2
    Else
        $_nh = $h
        $_ny = 0
        $_nw = $_iw * $_ZoomRatio
        $_nx = ($w - $_nw) / 2
    EndIf
    _GDIPlus_GraphicsDrawImageRect($_hGraphic, $_hImage, $_nx, $_ny, $_nw, $_nh)
    Local $_hHBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($_hBmp)
    ; set new image into list
    Local $_Indx = _GUIImageList_Add($hListImage, $_hHBMP)
    ; dispose objects
    _GDIPlus_ImageDispose($_hBmp)
    _GDIPlus_GraphicsDispose($_hGraphic)
    _GDIPlus_ImageDispose($_hImage)
    _WinAPI_DeleteObject($_hHBMP)
    _GDIPlus_GraphicsDispose($__hGraphic)
    Return $_Indx
EndFunc   ;==>_GDIPlusImageList_AddBitmap