#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Include <GDIPlus.au3>
Global $IFIlE[1] = [0]
Global $Path = IniRead (@ScriptDir & "\config.ini","INI","Path",@ScriptDir) ;图片的路径,默认为程序目录,目录后面不需要加""
Global $Time = IniRead (@ScriptDir & "\config.ini","INI","Time",3000) ;播放间隔,默认为3000ms(3秒).
;Global $IMAGEWidth = IniRead (@ScriptDir & "\config.ini","INI","Width",@DesktopWidth) ;图片控件的宽度,默认为屏幕宽度.
;Global $IMAGEHeight = IniRead (@ScriptDir & "\config.ini","INI","Height",@DesktopHeight) ;图片控件的高度,默认为屏幕高度.
Global Const $Form = GUICreate ("IMAGE Player",@DesktopWidth,@DesktopHeight,0,0,$WS_POPUP)
;~ Global Const $IMAG = GUICtrlCreatePic ("",(@DesktopWidth-$IMAGEWidth)/2,(@DesktopHeight-$IMAGEHeight)/2,$IMAGEWidth,$IMAGEHeight)
HotKeySet("{esc}","quit") ;;;按ESC退出
GUISetBkColor (0x000000,$Form)
GUISetState (@SW_SHOW)
Global $Search = FileFindFirstFile($Path & "\*.*")
If $Search = -1 Then
MsgBox(4096, "错误1", "没有找到图像文件。")
Exit
EndIf
;--------------------------------
;搜索目录下的图片
$i = 1
While 1
Local $File = FileFindNextFile($Search)
If @error Then ExitLoop
$Order = StringInStr($File,".",0,-1) ;;;从后往前查找文件名中的点
$FileType = StringMid($File,$Order + 1) ;;根椐文件名中的点的位置获取文件类型
;~ ConsoleWrite($File & " " & $FileType & @CRLF)
If $FileType = "jpg" Or $FileType = "gif" Or $FileType = "png" Or $FileType = "jpeg" Then ;;;如果是指定的几种类型
_ArrayAdd ($IFIlE,$Path & "" & $File)
$IFIlE[0] = $i
$i += 1
EndIf
WEnd
ConsoleWrite("总图片数 $IFIlE[0]:" & $IFIlE[0] & @CRLF)
If $IFIlE[0] = 0 Then
MsgBox(4096, "错误2", "没有找到图像文件。")
Exit
EndIf
;--------------------------------
_GDIPlus_Startup()
;--------------------------------
While 1
$Msg = GUIGetMsg()
If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
For $i = 1 To $IFile[0] - 1
ConsoleWrite($IFile[$i] & @CRLF)
$hBitmap = _GDIPlus_BitmapCreateFromFile($IFile[$i])
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form)
$Width = _GDIPlus_ImageGetWidth($hBitmap)
$Hight = _GDIPlus_ImageGetHeight($hBitmap)
ConsoleWrite("原图: $Width: " & $Width & " $Hight: " & $Hight & @CRLF)
If $Width >= @DesktopWidth Then ;;如果图片宽度超出屏幕宽度
$math = (@DesktopWidth / $Width)
$Width = Floor($Width * $math) ;;按比例缩放图片
$Hight = Floor($Hight * $math) ;;按比例缩放图片
EndIf
$x = Int((@DesktopWidth - $Width) / 2)
If $Hight >= @DesktopHeight Then ;;如果图片高度超出屏幕高度
$math = (@DesktopHeight / $Hight)
$Width = Floor($Width * $math) ;;按比例缩放图片
$Hight = Floor($Hight * $math) ;;按比例缩放图片
EndIf
$y = Int((@DesktopHeight - $Hight )/2)
ConsoleWrite("缩放后:$Width: " & $Width & " $Hight: " & $Hight & " $x: " & $x & " $y: "& $y & @CRLF)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $x ,$y,$Width,$Hight)
Sleep($Time)
_GDIPlus_GraphicsClear($hGraphic) ;;刷新会有闪烁感,不刷新会有上一张图的重影,不知道怎么处理
Next
WEnd
; 关闭 GDI+ 库
_GDIPlus_Shutdown()
Func quit() ;;按ESC键退出
_GDIPlus_Shutdown()
Exit
EndFunc
为了解决图片分辨率的问题,把楼上的代码改改,但运行起来内存一直在增加,不知道怎么处理。