#cs ---------------------------------------------------------------------------- AutoIt Version : 3.3.12.0 Auteur: Jonathan Fonction du Script : Modèle de Script AutoIt. #ce ---------------------------------------------------------------------------- ; Début du script - Ajouter votre code ci-dessous. #pragma compile(Icon, C:\Program Files (x86)\AutoIt3\Icons\au3.ico) #include #include #include #include #include #include #include #include #include #Region ### START Koda GUI section ### Form=C:\Users\Jonathan\Documents\Programmation\AutoIt\Projets\PEL2 Fragmenteur\Form1.kxf Global $Form1 = GUICreate("Fragmenteur d'images", 800, 568, 296, 170) Global $Label1 = GUICtrlCreateLabel("Fragmentez aisément vos images avec Fragmenteur d'images !", 40, 40, 296, 17) Global $Group1 = GUICtrlCreateGroup("Paramètres : ", 24, 88, 321, 401) Global $Label2 = GUICtrlCreateLabel("Chemin de l'image :", 40, 128, 95, 17) Global $Combo1 = GUICtrlCreateCombo("A8", 168, 160, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "A7|A6|A5|A4|A3|A2|A1|A0") Global $Label3 = GUICtrlCreateLabel("Format des fragments :", 40, 168, 111, 17) Global $Button1 = GUICtrlCreateButton("...", 296, 128, 27, 17) Global $Label4 = GUICtrlCreateLabel("...", 144, 128, 130, 17) Global $Label5 = GUICtrlCreateLabel("Unité :", 40, 232, 35, 17) Global $Combo2 = GUICtrlCreateCombo("cm", 168, 232, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "pixels") Global $Label6 = GUICtrlCreateLabel("Longueur :", 40, 272, 55, 17) Global $Label7 = GUICtrlCreateLabel("Largeur :", 40, 312, 46, 17) Global $Input1 = GUICtrlCreateInput("5.2", 168, 272, 121, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Input2 = GUICtrlCreateInput("7.4", 168, 312, 121, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Label8 = GUICtrlCreateLabel("Chemin de sortie :", 40, 368, 88, 17) Global $Label9 = GUICtrlCreateLabel("...", 136, 368, 130, 17) Global $Button2 = GUICtrlCreateButton("...", 294, 365, 27, 17) Global $Label10 = GUICtrlCreateLabel("Nombre de fragments : ", 40, 408, 114, 17) Global $Input3 = GUICtrlCreateInput("0", 168, 400, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER)) GUICtrlSetState(-1, $GUI_DISABLE) Global $Button3 = GUICtrlCreateButton("Fragmenter", 128, 456, 89, 25) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Group2 = GUICtrlCreateGroup("Prévisualisation", 392, 88, 377, 409) Global $Pic1 = GUICtrlCreatePic("", 416, 120, 329, 361) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ### START Koda GUI section ### Form=C:\Users\Jonathan\Documents\Programmation\AutoIt\Projets\PEL2 Fragmenteur\Form2.kxf Global $Form2 = GUICreate("Fragmenteur d'images - Fragmentation en cours...", 459, 161, 507, 263) Global $Label11 = GUICtrlCreateLabel("Chemin du fragment : ", 8, 64, 260, 17) Global $Label12 = GUICtrlCreateLabel("Fragment numéro : ", 8, 32, 120, 17) Global $Label13 = GUICtrlCreateLabel("Fragments restants : ", 8, 96, 120, 17) Global $Label14 = GUICtrlCreateLabel("Progression : ", 8, 128, 68, 17) Global $Progress1 = GUICtrlCreateProgress(112, 128, 329, 17, $PBS_SMOOTH) Global $Label15 = GUICtrlCreateLabel("Temps écoulé : ", 288, 32, 180, 17) Global $Label16 = GUICtrlCreateLabel("Temps restant estimé : ", 288, 64, 180, 17) GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### _GDIPlus_Startup() #region VARIABLES Global $inputDir, $outputDir, $f_Width, $f_Height, $r_Width, $r_Height, $f_Type, $f_unit, $g_Width = 329, $g_Height = 361, $pixelCoeff = 28 ; 1 cm => pixels 37.79527559055 Global $graphHdlArea = GUICtrlGetHandle($Pic1), $graphHdl = _GDIPlus_GraphicsCreateFromHWND($graphHdlArea), $brownPenHdl = _GDIPlus_PenCreate(0xFFAA0000), $mainBitmapHdl, $outDated = True, $originalColor = 0xFFF0F0F0 Global $fragsNbr = 0, $filename Global $globalTimerHdl, $timeSpent, $timeLeft #EndRegion #region FORMAT LIST Global $formatList[9][3] = [ _ ["A0", 84.1, 118.9], _ ["A1", 59.4, 84.1], _ ["A2", 42, 59.4], _ ["A3", 29.7, 42], _ ["A4", 21, 29.7], _ ["A5", 14.8, 21], _ ["A6", 10.5, 14.8], _ ["A7", 7.4, 10.5], _ ["A8", 5.2, 7.4] ] Global $unitList[2] = ["cm","pixel"] #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GDIClear() Exit Case $Button1 Local $tempImageDir, $temp $tempImageDir = FileOpenDialog("Choisissez l'image à fragmenter...",@ScriptDir,"JPG (*.jpg)|Bitmap (*.bmp)|PNG (*.png)") If _IsImageDir($tempImageDir) Then $inputDir = $tempImageDir If Stringlen($inputDir) < 24 Then GUICtrlSetData($Label4,$inputDir) Else $temp = StringSplit($inputDir,"\") GUICtrlSetData($Label4,$temp[1] & "\...\" & $temp[$temp[0]]) EndIf $filename = _GetFileName($inputDir) $outDated = True Else GUICtrlSetData($Label4,"...") EndIf Case $Button2 Local $tempFolderDir, $temp $tempFolderDir = FileSelectFolder("Choisissez le dossier de destination des fragments...",@ScriptDir) If _IsFolderDir($tempFolderDir) Then $outputDir = $tempFolderDir If Stringlen($outputDir) < 24 Then GUICtrlSetData($Label9,$outputDir) Else $temp = StringSplit($outputDir,"\") GUICtrlSetData($Label9,$temp[1] & "\...\" & $temp[$temp[0]]) EndIf Else GUICtrlSetData($Label9,"...") EndIf Case $Combo1 $outDated = True Case $Button3 GUISetState(@SW_HIDE,$Form1) GUISetState(@SW_SHOW,$Form2) _CreateFragments() GUISetState(@SW_HIDE,$Form2) GUISetState(@SW_SHOW,$Form1) $outDated = True EndSwitch _LoadFSetting() If _IsImageDir($inputDir) And $outDated Then $mainBitmapHdl = _GDIPlus_BitmapCreateFromFile($inputDir) _GDIPlus_GraphicsDrawImage($graphHdl,$mainBitmapHdl,0,0) _DrawScaledImage() _DrawScaledFragments() $outDated = False EndIf If GUICtrlGetState($Button3) = $GUI_DISABLE + $GUI_SHOW And _IsImageDir($inputDir) And _IsFolderDir($outputDir) Then GUICtrlSetState($Button3,$GUI_ENABLE) ElseIf GUICtrlGetState($Button3) = $GUI_ENABLE + $GUI_SHOW And (Not _IsImageDir($inputDir) Or Not _IsFolderDir($outputDir)) Then GUICtrlSetState($Button3,$GUI_DISABLE) EndIf Sleep(20) WEnd #region FONCTIONS TEST Func _IsFormat($format) Local $i = 0, $ret = False While ( Not($ret) And $i < 9) If $formatList[$i][0] = $format Then $ret = True $i += 1 WEnd Return $ret EndFunc Func _IsUnit($unit) Local $i = 0, $ret = False While ( Not($ret) And $i < 2) If $unit = $unitList[$i] Then $ret = True $i += 1 WEnd Return $ret EndFunc Func _IsImageDir($imageDir) Local $ret = False, $temp $temp = StringSplit($imageDir,".") If Not @error Then If (FileExists($imageDir) And ($temp[UBound($temp)-1] = "jpg" Or $temp[UBound($temp)-1] = "bmp" Or $temp[UBound($temp)-1] = "png")) Then $ret = True EndIf Return $ret EndFunc Func _IsFolderDir($folderDir) Local $ret = False, $temp $temp = StringSplit($folderDir,"\") If Not @error Then If (FileExists($folderDir) And $temp[UBound($temp)-1] <> "") Then $ret = True EndIf Return $ret EndFunc #EndRegion #Region FONCTIONS ACCESS Func _GetFormatRow($format) Local $i = 0 While ($format <> $formatList[$i][0]) $i += 1 WEnd Return $i EndFunc Func _LoadFSetting() Local $temp $temp = GUICtrlRead($Combo1) If Not _IsFormat($temp) Then $temp = "A4" $f_Type = $temp $temp = _GetFormatRow($f_Type) $f_Width = $pixelCoeff*$formatList[$temp][1] $f_Height = $pixelCoeff* $formatList[$temp][2] ; unité en pixel $temp = GUICtrlRead($Combo2) If Not _IsUnit($temp) Then $f_unit = "cm" $f_unit = $temp If $f_unit = "cm" Then GUICtrlSetData($Input1, $f_Width/$pixelCoeff) GUICtrlSetData($Input2, $f_Height/$pixelCoeff) Else GUICtrlSetData($Input1, $f_Width) GUICtrlSetData($Input2, $f_Height) EndIf EndFunc Func _GetFileName($imageDir) Local $temp, $ret, $i $temp = Stringsplit($imageDir,"\") $ret = $temp[$temp[0]] $temp = StringSplit($ret,".") $ret = "" For $i = 1 To $temp[0]-1 $ret &= $temp[$i] Next Return $ret EndFunc #EndRegion #region GDI Func _GDIClear() _GDIPlus_PenDispose($brownPenHdl) _GDIPlus_GraphicsDispose($graphHdl) _GDIPlus_BitmapDispose($mainBitmapHdl) _GDIPlus_Shutdown() EndFunc Func _DrawScaledImage() Local $alpha, $tempBitmapHdl $r_Width = _GDIPlus_ImageGetWidth($mainBitmapHdl) $r_Height = _GDIPlus_ImageGetHeight($mainBitmapHdl) If ( ($r_Height > $g_Height) Or ($r_Width > $g_Width) ) Then $alpha = _Max(($r_Height/$g_Height), ($r_Width/$g_Width)) EndIf _GDIPlus_GraphicsClear($graphHdl,$originalColor) $tempBitmapHdl = _GDIPlus_ImageResize($mainBitmapHdl,Floor($r_Width/$alpha), Floor($r_Height/$alpha)) _GDIPlus_GraphicsDrawImage($graphHdl,$tempBitmapHdl,0,0) _GDIPlus_BitmapDispose($tempBitmapHdl) EndFunc Func _DrawScaledFragments() Local $alpha, $i = 0, $j = 0 $fragsNbr = 0 $r_Width = _GDIPlus_ImageGetWidth($mainBitmapHdl) $r_Height = _GDIPlus_ImageGetHeight($mainBitmapHdl) If ( ($r_Height > $g_Height) Or ($r_Width > $g_Width) ) Then $alpha = _Max(($r_Height/$g_Height), ($r_Width/$g_Width)) EndIf While ($i < $r_Height) While ($j < $r_Width) If ($j + $f_Width > $r_Width) Then If ($i + $f_Height > $r_Height) Then _GDIPlus_GraphicsDrawRect($graphHdl,Floor($j/$alpha),Floor($i/$alpha),Floor(($f_Width - ($j + $f_Width - $r_Width + 1))/$alpha),Floor(($f_Height - ($i + $f_Height - $r_Height + 1))/$alpha),$brownPenHdl) Else _GDIPlus_GraphicsDrawRect($graphHdl,Floor($j/$alpha),Floor($i/$alpha),Floor(($f_Width - ($j + $f_Width - $r_Width + 1))/$alpha),Floor($f_Height/$alpha),$brownPenHdl) EndIf Else If ($i + $f_Height > $r_Height) Then _GDIPlus_GraphicsDrawRect($graphHdl,Floor($j/$alpha),Floor($i/$alpha),Floor($f_Width/$alpha),Floor(($f_Height - ($i + $f_Height - $r_Height+1))/$alpha),$brownPenHdl) Else _GDIPlus_GraphicsDrawRect($graphHdl,Floor($j/$alpha),Floor($i/$alpha),Floor($f_Width/$alpha),Floor($f_Height/$alpha),$brownPenHdl) EndIf EndIf $j += Floor($f_Width) $fragsNbr += 1 WEnd $j = 0 If ($i + $f_Height > $r_Height) Then $i += $f_Height - ($i + $f_Height - $r_Height) Else $i += $f_Height EndIf WEnd GUICtrlSetData($Input3,$fragsNbr) EndFunc Func _CreateFragments() Local $alpha, $i = 0, $j = 0, $fragsNum = 1, $tempBitmapHdl, $temp Local $localTimerHdl, $tempTime1, $tempTime2 Local $progCoeff = 100 / $fragsNbr $r_Width = _GDIPlus_ImageGetWidth($mainBitmapHdl) $r_Height = _GDIPlus_ImageGetHeight($mainBitmapHdl) $globalTimerHdl = TimerInit() While ($i < $r_Height) While ($j < $r_Width) $localTimerHdl = TimerInit() If $j + $f_Width > $r_Width Then If $i + $f_Height > $r_Height Then $tempBitmapHdl = _GDIPlus_BitmapCloneArea($mainBitmapHdl,$j,$i,Floor($f_Width - ($j + $f_Width - $r_Width + 1)),Floor($f_Height - ($i + $f_Height - $r_Height + 1))) Else $tempBitmapHdl = _GDIPlus_BitmapCloneArea($mainBitmapHdl,$j,$i,Floor($f_Width - ($j + $f_Width - $r_Width + 1)),Floor($f_Height)) EndIf Else If $i + $f_Height > $r_Height Then $tempBitmapHdl = _GDIPlus_BitmapCloneArea($mainBitmapHdl,$j,$i,Floor($f_Width),Floor($f_Height - ($i + $f_Height - $r_Height + 1))) Else $tempBitmapHdl = _GDIPlus_BitmapCloneArea($mainBitmapHdl,$j,$i,Floor($f_Width),Floor($f_Height)) EndIf EndIf $j += $f_Width _GDIPlus_ImageSaveToFile($tempBitmapHdl,$outputDir & "\" & $filename & "_frag_" & $fragsNum & ".bmp") $tempTime1 = TimerDiff($globalTimerHdl) $tempTime2 = TimerDiff($localTimerHdl) $timeSpent = _ConvertToTime($tempTime1) $timeLeft = _ConvertToTime($tempTime2 * ($fragsNbr - $fragsNum)) $temp = StringSplit($outputDir & "\" & $filename & "_frag_" & $fragsNum & ".bmp","\") GUICtrlSetData($Label11,"Chemin du fragment : " & $temp[1] & "\...\" & $temp[$temp[0]]) GUICtrlSetData($Label12,"Fragment numéro : " & $fragsNum) GUICtrlSetData($Label13,"Fragments restants : " & $fragsNbr-$fragsNum) GUICtrlSetData($Label15,"Temps écoulé : " & $timeSpent) GUICtrlSetData($Label16,"Temps restant : " & $timeLeft) GUICtrlSetData($Progress1,$progCoeff *$fragsNum) $fragsNum += 1 Sleep(10) WEnd $j = 0 If ($i + $f_Height > $r_Height) Then $i += $f_Height - ($i + $f_Height - $r_Height) Else $i += $f_Height EndIf WEnd _GDIPlus_BitmapDispose($tempBitmapHdl) MsgBox(64,"Fragmenteur d'images","La fragmentation est terminée !") EndFunc Func _ConvertToTime($length) Local $hour, $min, $sec, $ms, $temp $ms = $length $sec = Floor($ms/1000) $ms = Mod($ms,1000) $min = Floor($sec/60) $sec = Mod($sec,60) $hour = Floor($min/60) $min = Mod($min,60) Return $hour & "H" & $min & "MIN" & $sec & "SEC" ; a = bq + r EndFunc #EndRegion