找回密码
 加入
搜索
查看: 2097|回复: 3

[AU3基础] png图片替换

[复制链接]
发表于 2011-6-2 14:57:02 | 显示全部楼层 |阅读模式
我自己做了一个插入png图片的源码,还有替换图片的,可替换的过程会闪,希望大家能改一改,或者给个udf。
Func _GUICtrlCreatePic($filedir,$left = 0,$top = 0)
        Local Const $STM_SETIMAGE = 0x0172
        Local Const $STM_GETIMAGE = 0x0173

        Local $hForm,$Pic,$hPic,$hBitmap,$hObj,$hImage,$hStream,$bData,$hData,$pData,$tData,$Lenght,$open
        $open = FileOpen($filedir,16)
        $bData = FileRead($open)
        FileClose($open)
        $Lenght = BinaryLen($bData)
        $hData = _MemGlobalAlloc($Lenght,2)
        $pData = _MemGlobalLock($hData)
        $tData = DllStructCreate("byte[" & $Lenght & "]",$pData)
        DllStructSetData($tData,1,$bData)
        _MemGlobalUnlock($hData)
        $hStream = _WinAPI_CreateStreamOnHGlobal($hData)
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromStream($hStream)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $Width = _GDIPlus_ImageGetWidth($hImage)
        $Height = _GDIPlus_ImageGetHeight($hImage)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        $Pic = GUICtrlCreatePic("",$left,$top,$Width,$Height)
        $hPic = GUICtrlGetHandle($Pic)
        _SendMessage($hPic,$STM_SETIMAGE,0,$hBitmap)
        $hObj = _SendMessage($hPic,$STM_GETIMAGE)
        _WinAPI_DeleteObject($hBitmap)
        Return $Pic
EndFunc

Func _GUICtrlSetPic($id,$filedir)
        Local Const $STM_SETIMAGE = 0x0172
        Local Const $STM_GETIMAGE = 0x0173
        Local $hForm,$Pic,$hPic,$hBitmap,$hObj,$hImage,$hStream,$bData,$hData,$pData,$tData,$Width,$Height,$Lenght,$open
        $open = FileOpen($filedir,16)
        $bData = FileRead($open)
        FileClose($open)
        $Lenght = BinaryLen($bData)
        $hData = _MemGlobalAlloc($Lenght,2)
        $pData = _MemGlobalLock($hData)
        $tData = DllStructCreate("byte[" & $Lenght & "]",$pData)
        DllStructSetData($tData,1,$bData)
        _MemGlobalUnlock($hData)
        $hStream = _WinAPI_CreateStreamOnHGlobal($hData)
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromStream($hStream)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        $hPic = GUICtrlGetHandle($id)
        _SendMessage($hPic,$STM_SETIMAGE)
        _SendMessage($hPic,$STM_SETIMAGE,0,$hBitmap)
        _SendMessage($hPic,$STM_GETIMAGE)
        _WinAPI_DeleteObject($hBitmap)
        Return 1
EndFunc

Func _GUICtrlDeletPic($id)
        GUICtrlDelete($id)
EndFunc

Func _chuxiancishu($string,Const $find)
        Local $return = 0
        Local $stringlen = StringLen($find)
        While StringInStr($string,$find)
                $string = StringTrimLeft($string,StringInStr($string,$find) + $stringlen - 1)
                $return += 1
        WEnd
        Return $return
EndFunc

Func _GDIPlus_BitmapCreateFromStream($hStream)

    Local $aResult = DllCall($ghGDIPDll,"uint","GdipCreateBitmapFromStream","ptr",$hStream,"ptr*",0)

    If @error Then
        Return SetError(@error,@extended,0)
    EndIf
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream
发表于 2011-6-2 21:34:01 | 显示全部楼层
占楼研究...
发表于 2011-6-2 22:34:22 | 显示全部楼层
看不懂,帮顶
发表于 2011-6-12 09:52:39 | 显示全部楼层
我也版定一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-11 01:07 , Processed in 0.087136 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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