#include <array.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
Global $path = @WindowsDir & "\Web\Wallpaper"
;Global $path = "C:\Documents and Settings\Administrator\My Documents\test"
Global $ts_size
Global $number = 0
Global $jpg = _FileListToArray($path, "*.jpg")
Dim $w_picctrl = 698, $h_picctrl = 528
$Form1 = GUICreate('图片浏览器', 800, 630, -1, -1, -1, 0x00000010)
GUICtrlCreateGraphic(50, 10, $w_picctrl + 2, $h_picctrl + 2)
GUICtrlSetGraphic(-1, 10, 0, 0, $w_picctrl + 2, $h_picctrl + 2)
$pic = GUICtrlCreatePic('', 11, 11, 1, 1)
If IsArray($jpg) Then show($path & "" & $jpg[1])
$Button_forward = GUICtrlCreateButton("上一张", 269, 545, 97, 33)
$Button_next = GUICtrlCreateButton("下一张", 409, 545, 97, 33)
$Button_amp = GUICtrlCreateButton("放大图片", 269, 585, 97, 33)
$Button_narrow = GUICtrlCreateButton("缩小图片", 409, 585, 97, 33)
GUICtrlCreateLabel('图片原始像素:', 50, 550, 90, 17)
$ts_size = GUICtrlCreateLabel('', 140, 550, 100, 17)
GUISetState()
While 1
Sleep(1)
$SeeImageNmsg = GUIGetMsg()
Select
Case $SeeImageNmsg = $Button_next;点击下一张按钮响应的消息
If IsArray($jpg) Then
If $number >= $jpg[0] Then $number = 0
show($path & "" & $jpg[$number + 1])
$number += 1
EndIf
Case $SeeImageNmsg = $Button_forward;点击上一张按钮响应的消息
If IsArray($jpg) Then
If $number = 0 Or $number = 1 Then $number = $jpg[0] + 1
show($path & "" & $jpg[$number - 1])
$number -= 1
EndIf
Case $SeeImageNmsg = $Button_amp;恳请高手在这里加入图片放大代码
Case $SeeImageNmsg = $Button_narrow;恳请高手在这里加入图片缩小代码
Case $SeeImageNmsg = $GUI_EVENT_CLOSE ; Close Window关闭窗体
GUIDelete($Form1)
_GDIPlus_Shutdown(); 关闭 GDI+ 库
Exit
EndSelect
WEnd
Func Show($jpg_name)
Local $imgfile = $jpg_name, $hImage, $h_img
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($imgfile)
$w_img = _GDIPlus_ImageGetWidth($hImage)
$h_img = _GDIPlus_ImageGetHeight($hImage)
If $w_img * $h_img = 0 Then
_GDIPlus_Shutdown()
Return MsgBox(48, @error, '非图片格式', '', $Form1)
EndIf
GUICtrlSetData($ts_size, $w_img & ' x ' & $h_img);显示图片原始像素
Local $kgb = $h_picctrl / $w_picctrl
Local $kgb1 = $h_img / $w_img
Local $x_py = 0, $y_py = 0, $hBMP, $hObject
If $w_img > $w_picctrl Or $h_img > $h_picctrl Then
If $kgb1 > $kgb Then
$h_img = $h_picctrl
$w_img = Round(1 / $kgb1 * $h_img)
$x_py = ($w_picctrl - $w_img) / 2
Else
$w_img = $w_picctrl
$h_img = Round($kgb1 * $w_img)
$y_py = ($h_picctrl - $h_img) / 2
EndIf
Else
$x_py = ($w_picctrl - $w_img) / 2
$y_py = ($h_picctrl - $h_img) / 2
EndIf
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hObject = GUICtrlSendMsg($pic, 0x0172, 0, $hBMP)
_WinAPI_DeleteObject($hObject)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
GUICtrlSetPos($pic, 51 + $x_py - 1, 11 + $y_py - 1, $w_img, $h_img)
GUICtrlSetPos($pic, 51 + $x_py, 11 + $y_py)
EndFunc ;==>Show