求各位大神帮忙写一个图片播放器。
要求:打开程序全屏播放当前目录IMG文件夹下面的所以图片。图片的分辨率最后可以手动用INI文件配置。 本帖最后由 FluxayX 于 2015-5-22 14:22 编辑
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Global $IFIlE
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 $Search = FileFindFirstFile($Path & "*.jpg")
Global Const $Form = GUICreate ("IMAGE Player",@DesktopWidth,@DesktopHeight,0,0,$WS_POPUP)
Global Const $IMAG = GUICtrlCreatePic ("",(@DesktopWidth-$IMAGEWidth)/2,(@DesktopHeight-$IMAGEHeight)/2,$IMAGEWidth,$IMAGEHeight)
GUISetBkColor (0x000000,$Form)
GUISetState (@SW_SHOW)
;--------------------------------
;搜索目录下的图片
For $i = 0 To 200 Step 1
Local $File = FileFindNextFile($Search)
If @error Then ExitLoop
ReDim $IFIlE[$i]
_ArrayAdd ($IFIlE,$File)
Next
;--------------------------------
$i = 0
While 1
$Msg = GUIGetMsg()
If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
GUICtrlSetImage ($IMAG,$Path & $IFIlE[$i])
FileCopy ($Path & $IFIlE[$i],@DesktopDir & "\Temp\" & $i & ".jpg")
Sleep ($Time)
$i += 1
If $i = UBound($IFIlE) Then $i = 0
WEnd
上面是主程序,依据配置文件读取图片目录,播放图片延迟,图片大小.
下面是配置文件↓;配置文件的名字务必为:config.ini
Path=
;不填的话图片就得和脚本放在同一目录
Time=100
;延迟(毫秒),为了测试填了100
Width=1440
;图片控件的宽度
Height=900
;图片控件的高度
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Include <GDIPlus.au3>
Global $IFIlE =
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 = $i
$i += 1
EndIf
WEnd
ConsoleWrite("总图片数 $IFIlE:" & $IFIlE & @CRLF)
If $IFIlE = 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 - 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为了解决图片分辨率的问题,把楼上的代码改改,但运行起来内存一直在增加,不知道怎么处理。
用SLEPP会导致窗口很难关闭,所以加了一个ESC热键退出。 本帖最后由 luren666 于 2015-5-24 10:52 编辑
搞不明白WIN8的宽屏笔记本,屏幕分辨率是1920*1080,但是@DesktopWidth 和 @DesktopHeight 却是1536*864 。
页:
[1]