gdi如何清除图片4个角的杂色部分(已解决)
本帖最后由 shenrenba 于 2014-10-22 07:56 编辑如图
顺便问个问题 如下图代码最小化后窗体就变成空白了 如何解决
图片附件
测试代码#include <Gdiplus.au3>
$gui=GUICreate("",200,100)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$image1="1111.bmp"
$image2="2222.bmp"
$loadimage=_GDIPlus_ImageLoadFromFile($image2)
$imagewidth=_GDIPlus_ImageGetWidth($loadimage)
$imageheight=_GDIPlus_ImageGetHeight($loadimage)
$grapgics=_GDIPlus_GraphicsCreateFromHWND($gui)
$hbitmap=_GDIPlus_BitmapCreateFromGraphics(200,100,$grapgics)
_GDIPlus_GraphicsDrawImageRectRect($grapgics,$loadimage,5,5,$imagewidth-10,$imageheight-10,0,0,200,100)
_GDIPlus_ImageDispose($loadimage)
$loadimage=_GDIPlus_ImageLoadFromFile($image1)
$imagewidth=_GDIPlus_ImageGetWidth($loadimage)
$imageheight=_GDIPlus_ImageGetHeight($loadimage)
_GDIPlus_GraphicsDrawImageRectRect($grapgics,$loadimage,$imagewidth/5,0,$imagewidth/5,$imageheight,60,20,$imagewidth/5,$imageheight)
_GDIPlus_BitmapDispose($hbitmap)
_GDIPlus_GraphicsDispose($grapgics)
_GDIPlus_ImageDispose($loadimage)
_GDIPlus_Shutdown()
WhileGUIGetMsg()+3
WEnd 高,,这样也可以啊。。AU3功能不是一般的强啊 不能打开包含文件 <WinAPISys.au3>.
这是什么意思 回复 3# deaph
这个库文件可以删除(新版包含这个库文件)代码中没用到我在其他地方用了忘了删除 #include <Gdiplus.au3>
#include <GUIConstantsEx.au3>
$gui=GUICreate("",200,100)
GUISetState(@SW_SHOW)
GDI()
While1
$msg=GUIGetMsg()
Switch $msg
Case $GUI_EVENT_RESTORE
GDI()
Case -3
Exit
EndSwitch
WEnd
Func GDI()
_GDIPlus_Startup()
$image1="1111.bmp"
$image2="2222.bmp"
$loadimage=_GDIPlus_ImageLoadFromFile($image2)
$imagewidth=_GDIPlus_ImageGetWidth($loadimage)
$imageheight=_GDIPlus_ImageGetHeight($loadimage)
$grapgics=_GDIPlus_GraphicsCreateFromHWND($gui)
$hbitmap=_GDIPlus_BitmapCreateFromGraphics(200,100,$grapgics)
_GDIPlus_GraphicsDrawImageRectRect($grapgics,$loadimage,5,5,$imagewidth-10,$imageheight-10,0,0,200,100)
_GDIPlus_ImageDispose($loadimage)
$loadimage=_GDIPlus_ImageLoadFromFile($image1)
$imagewidth=_GDIPlus_ImageGetWidth($loadimage)
$imageheight=_GDIPlus_ImageGetHeight($loadimage)
_GDIPlus_GraphicsDrawImageRectRect($grapgics,$loadimage,$imagewidth/5,0,$imagewidth/5,$imageheight,60,20,$imagewidth/5,$imageheight)
_GDIPlus_BitmapDispose($hbitmap)
_GDIPlus_GraphicsDispose($grapgics)
_GDIPlus_ImageDispose($loadimage)
_GDIPlus_Shutdown()
EndFunc 回复 5# ap112
你这个只是窗体重绘 但是我最小化的不是本窗体是别的窗体会变空 另外不光最小化激活别的窗口也会变空的 GDI绘制本来就不可以保存,要是你想制作类似的窗口为什么不使用图片做背景,图标可以使用ico 象这个BMP图像,一般是用GDI来操作,楼主用的是GDI+,下面先给出GDI+去边角的一种方法.
要一直显示等会用GDI来再做。
#include <Gdiplus.au3>
$gui=GUICreate("",200,100)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$image1="1111.bmp"
$image2="2222.bmp"
$loadimage=_GDIPlus_ImageLoadFromFile($image2)
$imagewidth=_GDIPlus_ImageGetWidth($loadimage)
$imageheight=_GDIPlus_ImageGetHeight($loadimage)
$grapgics=_GDIPlus_GraphicsCreateFromHWND($gui)
$hbitmap=_GDIPlus_BitmapCreateFromGraphics(200,100,$grapgics)
$getcon=_GDIPlus_ImageGetGraphicsContext($hbitmap)
_GDIPlus_GraphicsSetSmoothingMode($getcon,2)
_GDIPlus_GraphicsDrawImageRectRect($grapgics,$loadimage,5,5,$imagewidth-10,$imageheight-10,0,0,200,100)
_GDIPlus_ImageDispose($loadimage)
$loadimage=_GDIPlus_ImageLoadFromFile($image1)
$imagewidth=_GDIPlus_ImageGetWidth($loadimage)
$imageheight=_GDIPlus_ImageGetHeight($loadimage)
;设置剪切区域-----------------
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddEllipse($hPath, 60, 20, 21, 21);60,20为圆形的左上角坐标,21,21是半径,应该是23可是本来的图片质量不高21较好看
_GDIPlus_GraphicsSetClipPath($grapgics, $hPath)
_GDIPlus_GraphicsDrawImageRectRect($grapgics,$loadimage,$imagewidth/5,0,$imagewidth/5,$imageheight,60,20,$imagewidth/5,$imageheight)
;释放剪切区域-----------
_GDIPlus_GraphicsResetClip($grapgics)
_GDIPlus_BitmapDispose($hbitmap)
_GDIPlus_GraphicsDispose($getcon)
_GDIPlus_GraphicsDispose($grapgics)
_GDIPlus_ImageDispose($loadimage)
_GDIPlus_Shutdown()
WhileGUIGetMsg()+3
WEnd GDI操作,并图像一直存在
#include <WindowsConstants.au3>
#Include <WinAPIEx.au3>
$image1="1111.bmp"
$image2="2222.bmp"
;让窗口的绘制交给函数OWNER_WM_PAINT
GUIRegisterMsg($WM_PAINT, "OWNER_WM_PAINT")
$hGui=GUICreate("",200,100)
GUISetState(@SW_SHOW)
WhileGUIGetMsg()+3
WEnd
;绘制函数OWNER_WM_PAINT
Func OWNER_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
;读入图像
Local $hTotalImage = _WinAPI_LoadImage(0, $image1, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
Local $hBackImage = _WinAPI_LoadImage(0, $image2, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
;WM_PAINT必须
Local $tPAINTSTRUCT
Local $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT)
;背景图像读入内存DC
Local $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hBackSv = _WinAPI_SelectObject($hBackDC, $hBackImage)
;图标图像读入内存DC
Local $hTotalDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hTotalSv = _WinAPI_SelectObject($hTotalDC, $hTotalImage)
;处理图标透明所需的掩码图像DC
Local $hMaskDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hMask = _WinAPI_CreateCompatibleBitmap($hDC, 23, 23)
Local $hMaskSv = _WinAPI_SelectObject($hMaskDC, $hMask)
_WinAPI_BitBlt($hMaskDC, 0,0,23,23,$hTotalDC,0,0,$NOTSRCCOPY);23是掩码图像的长宽,掩码在0,0
;掩码图像和所需图标XOR操作
Local $hTempDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hTemp = _WinAPI_CreateCompatibleBitmap($hDC, 23, 23)
Local $hTempSv = _WinAPI_SelectObject($hTempDC, $hTemp)
_WinAPI_BitBlt($hTempDC, 0,0,23,23,$hTotalDC,23,0,$SRCCOPY);所需图标在23,0、后一个在46,0
_WinAPI_BitBlt($hTempDC, 0,0,23,23,$hMaskDC,0,0,$SRCINVERT);掩码图像与图标XOR操作
;把背景图像拉伸绘制到窗口上
_WinAPI_StretchBlt($hDC, 0,0,200,100,$hBackDC,0,0,128,48,$SRCCOPY)
;把掩码图像和背景图像AND操作
_WinAPI_BitBlt($hDC, 60, 20, 23, 23,$hMaskDC, 0, 0, $SRCAND)
;把 “掩码图像和所需图标XOR操作” 合成后的图像 与 上面的掩码OR操作,完成透明
_WinAPI_BitBlt($hDC, 60, 20, 23, 23,$hTempDC, 0, 0, $SRCPAINT)
;删除用过的对象
_WinAPI_SelectObject($hTempDC, $hTempSv)
_WinAPI_SelectObject($hMaskDC, $hMaskSv)
_WinAPI_SelectObject($hBackDC, $hBackSv)
_WinAPI_SelectObject($hTotalDC, $hTotalSv)
_WinAPI_DeleteObject($hMask)
_WinAPI_DeleteObject($hTemp)
_WinAPI_DeleteObject($hTotalImage)
_WinAPI_DeleteObject($hBackImage)
_WinAPI_DeleteDC($hTotalDC)
_WinAPI_DeleteDC($hTempDC)
_WinAPI_DeleteDC($hMaskDC)
_WinAPI_DeleteDC($hBackDC)
Return _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT)
EndFunc
回复 9# seniors
3q研究下代码 回复 9# seniors
不记得你对gdi/gdi+有如此高的造诣啊 回复 11# netegg
还记得有这个人就好了,蛋蛋 回复 12# seniors
客气了,最近一直在研究这方面东西,妈的,比api难多了 回复seniors
不记得你对gdi/gdi+有如此高的造诣啊
netegg 发表于 2014-10-22 08:00 http://www.autoitx.com/images/common/back.gif
seniors出马 这些根本都不是事…… 很有价值研究一下代码
页:
[1]