|
本帖最后由 vv3509 于 2016-6-9 20:53 编辑 #include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <winapi.au3>
If $CmdLine[0] = "" Then
MsgBox(48, "注意", "本程序不需要直接运行" & @CRLF & "只要将需处理文件全选拖到程序图标即可", 5)
Else
For $i = 1 To $CmdLine[0]
IMAGE_FZ($CmdLine[$i], _getdir($CmdLine[$i]) & "" & _getfilename($CmdLine[$i])) ;这一行出问题
Next
EndIf
;~ IMAGE_FZ("1.jpg", "2.jpg")
;图片翻转90度
Func IMAGE_FZ($picpath, $fiename) ;入口文件,出口文件
$nAngle = 90 ;翻转角度
_GDIPlus_Startup()
$hImage2 = _GDIPlus_ImageLoadFromFile($picpath)
$iW = _GDIPlus_ImageGetWidth($hImage2)
$iH = _GDIPlus_ImageGetHeight($hImage2)
$hWnd = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($hWnd)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iH, $iW)
_WinAPI_ReleaseDC($hWnd, $hDC)
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")
_GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage2, 0, 0 - $iH)
_GDIPlus_MatrixDispose($hMatrix)
$CLSID = _GDIPlus_EncodersGetCLSID("BMP")
_GDIPlus_ImageSaveToFileEx($hImage1, $fiename, $CLSID)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
EndFunc ;==>IMAGE_FZ
Func _getdir($spath)
If StringRegExp($spath, '\\') Then
$sdir = StringRegExpReplace($spath, '\\[^\\]*单独的 IMAGE_FZ("1.jpg", "2.jpg") 运行没问题 但是改成上面的批量处理就没反应了, '')
Else
$sdir = ''
EndIf
Return ($sdir)
EndFunc ;==>_getdir
Func _getfilename($spath, $sflag = 0)
If $sflag = 0 Then
$sflag = 0
Else
$sflag = 1
EndIf
If $sflag = 0 Then
$sFileName = StringRegExpReplace($spath, '.+\\', '')
Else
$sFileName = StringRegExpReplace($spath, '.+\\', '')
$sFileName = StringRegExpReplace($sFileName, '\.[^\.]*单独的 IMAGE_FZ("1.jpg", "2.jpg") 运行没问题 但是改成上面的批量处理就没反应了, '')
EndIf
Return ($sFileName)
EndFunc ;==>_getfilename
Func _getfiletype($spath)
$sFiletype = StringRegExpReplace($spath, '.+\.', '')
Return ($sFiletype)
EndFunc ;==>_getfiletype
第6-12行:运行没反应
单独运行13行的 IMAGE_FZ("1.jpg", "2.jpg") 就没问题
用官方论坛的这个代码解决:Global $hBitmap, $hImage, $hImage, $sCLSID, $tData, $tParams, $nAngle = 1 ;翻转角度
If $CmdLine[0] = "" Then
MsgBox(48, "注意", "本程序不需要直接运行" & @CRLF & "只要将需处理文件全选拖到程序图标即可", 5)
Else
For $i = 1 To $CmdLine[0]
IMAGE_FZ($CmdLine[$i], _getdir($CmdLine[$i]) & "" & _getfilename($CmdLine[$i]), $nAngle)
Next
EndIf
Func IMAGE_FZ($picpath, $fiename, $nAng)
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($picpath)
_GDIPlus_ImageRotateFlip($hImage, $nAng)
_GDIPlus_ImageSaveToFile($hImage, $fiename)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
EndFunc ;==>IMAGE_FZ
Func _getdir($spath)
If StringRegExp($spath, '\\') Then
$sdir = StringRegExpReplace($spath, '\\[^\\]*, '')
Else
$sdir = ''
EndIf
Return ($sdir)
EndFunc ;==>_getdir
Func _getfilename($spath, $sflag = 0)
If $sflag = 0 Then
$sflag = 0
Else
$sflag = 1
EndIf
If $sflag = 0 Then
$sFileName = StringRegExpReplace($spath, '.+\\', '')
Else
$sFileName = StringRegExpReplace($spath, '.+\\', '')
$sFileName = StringRegExpReplace($sFileName, '\.[^\.]*, '')
EndIf
Return ($sFileName)
EndFunc ;==>_getfilename
Func _getfiletype($spath)
$sFiletype = StringRegExpReplace($spath, '.+\.', '')
Return ($sFiletype)
EndFunc ;==>_getfiletype
但还是想知道上面那个代码为什么不行? |
|