#include <GDIPlus.au3>
Local $touxiang, $msg, $w = 105, $h = 105
$Form1_1 = GUICreate('Form1', 365, 184)
$Group1 = GUICtrlCreateGroup('上传头像注意事项', 144, 8, 217, 105)
$Label1 = GUICtrlCreateLabel('第一行', 152, 24, 40, 17)
$Label2 = GUICtrlCreateLabel('第二行', 152, 40, 40, 17)
$Label3 = GUICtrlCreateLabel('第三行', 152, 56, 40, 17)
$Label4 = GUICtrlCreateLabel('第四行', 152, 72, 40, 17)
$Label5 = GUICtrlCreateLabel('第五行', 152, 88, 40, 17)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$Pic1 = GUICtrlCreatePic('', 16, 8, $w, $h)
$Button1 = GUICtrlCreateButton('打开图片文件', 40, 128, 105, 41)
$Button2 = GUICtrlCreateButton('保存', 192, 128, 105, 41)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
$touxiang = FileOpenDialog('请选择你的头像图片文件', '', '(*.gif;*.jpg;*.bmp)')
GUICtrlSetImage($Pic1, $touxiang)
Case $Button2
$filename = StringRegExp($touxiang, '.+\\(.+)\.([^\.]+)', 3)
If @error Then ContinueLoop MsgBox(48, '错误', '还未选择文件')
$O_pic = @DesktopDir & '\' & $filename[0] & '_new.' & $filename[1]
If FileExists($O_pic) Then $msg = MsgBox(1 + 48, '问题', $O_pic & ' 已存在,重建时需先删除原文件,是否确定?')
If $msg = 2 Then ContinueLoop
FileDelete($O_pic)
$hWnd = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($hWnd)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
_WinAPI_ReleaseDC($hWnd, $hDC)
_GDIPlus_Startup()
$hOut = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
$hIn = _GDIPlus_ImageLoadFromFile($touxiang)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hOut)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hIn, 0, 0, $w, $h)
$CLSID = _GDIPlus_EncodersGetCLSID($filename[1])
_GDIPlus_ImageSaveToFileEx($hOut, $O_pic, $CLSID)
_GDIPlus_ImageDispose($hOut)
_GDIPlus_ImageDispose($hIn)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
If FileExists($O_pic) Then MsgBox(64, '完成', '已生成新图片:' & $O_pic)
EndSwitch
WEnd