找回密码
 加入
搜索
查看: 2480|回复: 2

[图形处理] [已解决]图片旋转180度并另存为遇到问题,请大家帮忙

[复制链接]
发表于 2013-5-3 23:28:06 | 显示全部楼层 |阅读模式
本帖最后由 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 ... hlight=%B7%AD%D7%AA改写成旋转180度的代码,可是改了半天总是图像缺失的很厉害。
就是这一句怎么改都改的不是那么如意 _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0 - $iW , 0-$iH, $iW, $iH)希望大家能帮帮忙。
发表于 2013-5-4 12:07:06 | 显示全部楼层
#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

评分

参与人数 1金钱 +30 收起 理由
silvay22 + 30 厉害、佩服

查看全部评分

 楼主| 发表于 2013-5-4 12:44:13 | 显示全部楼层
哇,A版就是强,每次出手都极为完美!谢谢祝周末愉快!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-19 18:54 , Processed in 0.125061 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表