首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

pb9.0怎么实现透明图片

2012-04-28 
pb9.0如何实现透明图片?pb9.0能实现透明图片的功能吗?比如在盖公章的时候我要公章下面的字也能看见[解决办

pb9.0如何实现透明图片?
pb9.0能实现透明图片的功能吗?比如在盖公章的时候我要公章下面的字也能看见

[解决办法]
$PBExportHeader$w_test.srw 
forward 
global type w_test from window 
end type 
type p_1 from picture within w_test 
end type 
type bitmap from structure within w_test 
end type 
end forward 

global type bitmap from structure 
long bmtype 
long bmwidth 
long bmheight 
long bmwidthbytes 
long bmplanes 
long bmbitspixel 
blob bmbits 
end type 

global type w_test from window 
integer width = 2217 
integer height = 1428 
boolean titlebar = true 
string title = "Untitled " 
boolean controlmenu = true 
boolean minbox = true 
boolean maxbox = true 
boolean resizable = true 
long backcolor = 67108864 
string icon = "AppIcon! " 
boolean center = true 
event ue_paint pbm_paint 
p_1 p_1 
end type 
global w_test w_test 

type prototypes 
FUNCTION ulong GetPixel(ulong hdc,ulong px,ulong py) LIBRARY "gdi32.dll " 
Function uLong GetDC(uLong hwnd) LIBRARY "user32.dll " 
//Function uLong StretchBlt(uLong hdc,uLong xx,uLong yy,uLong nWidth,uLong nHeight,uLong hSrcDC,uLong xSrc,uLong ySrc,uLong nSrcWidth,uLong nSrcHeight,uLong dwRop) LIBRARY "gdi32.dll " 
Function uLong DeleteDC(uLong hdc) LIBRARY "gdi32.dll " 
Function uLong DeleteObject(uLong hObject) LIBRARY "gdi32.dll " 
Function uLong SelectObject(uLong hdc,uLong hObject) LIBRARY "gdi32.dll " 
Function uLong GetObjectBitmap( uLong hgdiobj, int cbBuffer, ref bitmap bm ) library "gdi32.dll " alias for GetObjectA 
Function uLong LoadImage(uLong hInst,ref String lpsz,uLong un1,uLong n1,uLong n2,uLong un2) LIBRARY "user32.dll " ALIAS FOR "LoadImageA " 
Function uLong CreateCompatibleDC(uLong hdc) LIBRARY "gdi32.dll " 
FUNCTION ulong ReleaseDC(ulong hwnd,ulong hdc) LIBRARY "user32.dll " 
Function uLong SetBkColor(uLong hdc,uLong crColor) LIBRARY "gdi32.dll " 
Function long CreateCompatibleBitmap ( long hdc, long nwidth, long nheight ) library "gdi32 " 
Function long CreateBitmap ( long nwidth, long nheight, long nplanes, long nbitcount, long lpbits ) library "gdi32 " 
Function uLong BitBlt(uLong hDestDC,uLong xx,uLong yy,uLong nWidth,uLong nHeight,uLong hSrcDC,uLong xSrc,uLong ySrc,uLong dwRop) LIBRARY "gdi32.dll " 
FUNCTION ulong SetBkMode(ulong hdc,ulong nBkMode) LIBRARY "gdi32.dll " 
end prototypes 

type variables 
constant long SRCCOPY = 13369376 
constant long NOTSRCCOPY = 3342344 
constant long SRCAND = 8913094 
constant long SRCINVERT = 6684742 

uLONG il_memDC,il_old,il_windc,il_outputdc 
ulong il_rgb 
//自己定义图片路径 
string is_cmenu_pic = 'C:\mis\RLZY\pic\captionbar_VAE.bmp ' 

boolean ib_init_paint = false 

integer ii_bmpwidth,ii_bmpheight 
end variables 

forward prototypes 


public subroutine wf_transparentblt (long dstdc, long srcdc, integer srcx, integer srcy, integer srcw, integer srch, integer dstx, integer dsty, long transcolor) 
public subroutine wf_paint () 
end prototypes 

event ue_paint;//wf_paint() 

end event 

public subroutine wf_transparentblt (long dstdc, long srcdc, integer srcx, integer srcy, integer srcw, integer srch, integer dstx, integer dsty, long transcolor); // DstDC - Device context into image is actually drawn 
// SrcDC - Device context of source to be made transparent in color TransColor 
// SrcX, SrcY, SrcW, SrcH - Rectangular region of source bitmap in pixels 
// DstX, DstY - Coordinates in OutDstDC where the transparent bitmap must go 
// TransColor - Transparent color 
// 输出透明图像到DstDC 
Long nRet,MonoMaskDC,hMonoMask,MonoInvDC,hMonoInv,hResultDst,ResultDstDC 
long ResultSrcDC,hResultSrc,hPrevMask,hPrevInv,hPrevSrc,hPrevDst 
long OldBC 
Integer OldMode 

//Create monochrome mask and inverse masks 
MonoMaskDC = CreateCompatibleDC(DstDC) 
MonoInvDC = CreateCompatibleDC(DstDC) 
//Create monochrome bitmaps for the mask-related bitmaps: 
hMonoMask = CreateBitmap(SrcW, SrcH, 1, 1, 0) 
hMonoInv = CreateBitmap(SrcW, SrcH, 1, 1, 0) 
hPrevMask = SelectObject(MonoMaskDC, hMonoMask) 
hPrevInv = SelectObject(MonoInvDC, hMonoInv) 
// Create keeper DCs and bitmaps 
ResultDstDC = CreateCompatibleDC(DstDC) 
ResultSrcDC = CreateCompatibleDC(DstDC) 
//Create color bitmaps for final result & stored copy of source 
hResultDst = CreateCompatibleBitmap(DstDC, SrcW, SrcH) 
hResultSrc = CreateCompatibleBitmap(DstDC, SrcW, SrcH) 
hPrevDst = SelectObject(ResultDstDC, hResultDst) 
hPrevSrc = SelectObject(ResultSrcDC, hResultSrc) 
// Copy src to monochrome mask 
OldBC = SetBkColor(SrcDC, TransColor) 
nRet = BitBlt(MonoMaskDC, 0, 0, SrcW, SrcH, SrcDC,SrcX, SrcY, SrcCopy) 
TransColor = SetBkColor(SrcDC, OldBC) 
//Create inverse of mask 
nRet = BitBlt(MonoInvDC, 0, 0, SrcW, SrcH, MonoMaskDC, 0, 0, NotSrcCopy) 
//Copy background bitmap to result & create final transparent bitmap 
nRet = BitBlt(ResultDstDC, 0, 0, SrcW, SrcH, DstDC, DstX, DstY, SrcCopy) 

//AND mask bitmap w/ result DC to punch hole in the background by 
//painting black area for non-transparent portion of source bitmap. 
nRet = BitBlt(ResultDstDC, 0, 0, SrcW, SrcH, MonoMaskDC, 0, 0, SrcAnd) 
// Get overlapper 
nRet = BitBlt(ResultSrcDC, 0, 0, SrcW, SrcH, SrcDC, SrcX, SrcY, SrcCopy) 
//AND inverse mask w/ source bitmap to turn off bits associated 
//with transparent area of source bitmap by making it black. 
nRet = BitBlt(ResultSrcDC, 0, 0, SrcW, SrcH, MonoInvDC, 0, 0, SrcAnd) 
//XOR result w/ source bitmap to make background show through. 


nRet = BitBlt(ResultDstDC, 0, 0, SrcW, SrcH, ResultSrcDC, 0, 0, SrcInvert) 
//Output results 
nRet = BitBlt(DstDC, DstX, DstY, SrcW, SrcH, ResultDstDC, 0, 0, SrcCopy) 
// Clean up 
hMonoMask = SelectObject(MonoMaskDC, hPrevMask) 
DeleteObject (hMonoMask) 
hMonoInv = SelectObject(MonoInvDC, hPrevInv) 
DeleteObject (hMonoInv) 
hResultDst = SelectObject(ResultDstDC, hPrevDst) 
DeleteObject (hResultDst) 
hResultSrc = SelectObject(ResultSrcDC, hPrevSrc) 
DeleteObject (hResultSrc) 
DeleteDC (MonoMaskDC) 
DeleteDC(MonoInvDC) 
DeleteDC (ResultDstDC) 
DeleteDC (ResultSrcDC) 
  

end subroutine 

public subroutine wf_paint ();ulong ll_bmp,ll_new 
bitmap lus_bmp 
long ll_inst 
SetNull(ll_inst) 
if il_windc = 0 and il_memdc =0 then 
il_windc = GetDC(Handle(this)) 
il_memDC = CreateCompatibleDC(il_windc) 
//载入图片 
ll_bmp = LoadImage(ll_inst,is_cmenu_pic,0,0,0,16) 
if ll_bmp = 0 then return
GetObjectBitmap( ll_bmp, 28, lus_bmp ) 
ii_bmpwidth= lus_bmp.bmwidth 
ii_bmpheight=lus_bmp.bmheight 
il_old = SelectObject(il_memDC,ll_bmp) 
il_rgb = GetPixel(il_memDC,0,0) 
//il_rgb为需要透明的颜色 
p_1.width = PixelsToUnits(ii_bmpwidth, XPixelsToUnits!) 
p_1.height= PixelsToUnits(ii_bmpheight, YPixelsToUnits!) 
end if 
//100,100为输出的位置 
wf_transparentblt(getdc(handle(p_1)),il_memDC,0,0,ii_bmpwidth,ii_bmpheight,0,0,il_rgb) 


end subroutine 

on w_test.create 
this.p_1=create p_1 
this.Control[]={this.p_1} 
end on 

on w_test.destroy 
destroy(this.p_1) 
end on 

event close;SelectObject(il_memDC,il_old) 
DeleteDC(il_memDC) 
DeleteDC(il_windc) 
end event 

type p_1 from picture within w_test 
event ue_paint pbm_paint 
integer x = 585 
integer y = 576 
integer width = 768 
integer height = 256 
boolean focusrectangle = false 
end type 

event ue_paint;wf_paint() 

return 1 
end event 

event constructor;this.ENABLED = FALSE 
end event
[解决办法]
原贴见

http://topic.csdn.net/t/20020919/14/1036903.html
[解决办法]
太复杂了这个、

热点排行