求助,为什么PNG图片不能显示出来?(已解决)
本帖最后由 夜猫猫 于 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
什么意思?是要将图片切成5份显示? 不是切割后显示,是直接获取后显示,就是没有输出图片。切割后显示我会。
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($PNG1) ;获取图像的图形环境
$hImage2 = _GDIPLus_GraphicsDrawImageRect($hGraphic, $PNG1, 0, 0, 47, 57)
这两句用法对吗? 额 css sprites表示鸭梨很大 本帖最后由 ceoguang 于 2011-7-28 19:04 编辑
#NoTrayIcon
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
_GDIPlus_Startup()
$pngSrc = @ScriptDir&"\b.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) ; 创建位图克隆
SetBitmap($GUI,$PNG1, 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
如此? 额。直接使用位图克隆就好,下面两个是多余的。又钻牛角了。{:face (394):} 这个确实显示了,可是无法在GUI放入输入框 看贴学习一下,不错支持……
页:
[1]