[已解决]图片旋转180度并另存为遇到问题,请大家帮忙
本帖最后由 silvay22 于 2013-5-4 12:44 编辑;图片旋转180度
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <winapi.au3>
IMAGE_FZ(@WindowsDir & "\Web\Wallpaper" & "\" & "Stonehenge.jpg", @WindowsDir & "\Web\Wallpaper" & "\" & "5.jpg")
Func IMAGE_FZ($picpath,$fiename);入口文件,出口文件
$nAngle=180;翻转角度
_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_GraphicsDrawImageRect($hGraphic, $hImage2, 0 - $iW , 0-$iH, $iW, $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本人将这段由大侠35888894 写的代码,原地址http://www.autoitx.com/forum.php?mod=viewthread&tid=36345&highlight=%B7%AD%D7%AA改写成旋转180度的代码,可是改了半天总是图像缺失的很厉害。
就是这一句怎么改都改的不是那么如意 _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0 - $iW , 0-$iH, $iW, $iH)希望大家能帮帮忙。 #include <GDIPlus.au3>
_GDIPlus_ImageRotateToSave('1.jpg', '111.jpg')
Func _GDIPlus_ImageRotateToSave($sPicPath, $sNewName)
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($sPicPath)
DllCall($ghGDIPDll, 'uint', 'GdipImageRotateFlip', 'hwnd', $hImage, 'int', 2)
_GDIPlus_ImageSaveToFile($hImage, $sNewName)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
EndFunc ;==>_GDIPlus_ImageRotateToSave 哇,A版就是强,每次出手都极为完美!谢谢祝周末愉快!
页:
[1]