本帖最后由 夜猫猫 于 2011-7-29 14:58 编辑
不想切割图片,省的都是图。需要获取图片中的一部分,并使其显示出来。
我的代码怎么不能显示?是不是少了什么
去掉分割的数值。PNG能正常显示。刚代码乱了。。
#NoTrayIcon
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
_GDIPlus_Startup()
$pngSrc = @ScriptDir&"\background.png"
$hImage = _GDIPlus_ImageLoadFromFile($pngSrc) ; 载入图片
$width = _GDIPlus_ImageGetWidth($hImage) ; 获得图片宽度
$height = _GDIPlus_ImageGetHeight($hImage) ;获得图片高度
$GUI = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED) ;创建无标题窗口
;==================================================
$PNG1 = _GDIPlus_BitmapCloneArea($hImage, 0, 0, 47, 57, 0x0026200A) ; 创建位图克隆
; 绘制另一幅图像
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($PNG1) ;获取图像的图形环境
$hImage2 = _GDIPLus_GraphicsDrawImageRect($hGraphic, $PNG1, 0, 0, 47, 57) ;图像绘制到指定的位置
;==================================================
;上面=====的部分去掉,将下面的 $hImage2改成 $hImage就能正常显示
SetBitmap($GUI, $hImage2, 255)
WinSetOnTop($GUI, "", 1);窗口置顶
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
;加载图象
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
|