如何通過Bitblt函數在任何背景上透明的畫出 Icon圖像(100分)

  • 主题发起人 主题发起人 abchjb
  • 开始时间 开始时间
这不能用简单的bitblt来完成吧
你可以参照TImage在设定Transparent后的Draw.
TImage.Draw...
....
if Transparent then
begin
Save := 0;
MaskDC := 0;
try
MaskDC := GDICheck(CreateCompatibleDC(0));
Save := SelectObject(MaskDC, FMaskHandle);
<font color="red">TransparentStretchBlt</font>(ACanvas.FHandle, Left, Top, Right - Left,
Bottom - Top, Canvas.FHandle, 0, 0, FDIB.dsbm.bmWidth,
FDIB.dsbm.bmHeight, MaskDC, 0, 0);
finally
if Save <> 0 then
SelectObject(MaskDC, Save);
if MaskDC <> 0 then
DeleteDC(MaskDC);
end;
end
....
function TransparentStretchBlt(DstDC: HDC;
DstX, DstY, DstW, DstH: Integer;
SrcDC: HDC;
SrcX, SrcY, SrcW, SrcH: Integer;
MaskDC: HDC;
MaskX,
MaskY: Integer): Boolean;
const
ROP_DstCopy = $00AA0029;
var
MemDC: HDC;
MemBmp: HBITMAP;
Save: THandle;
crText, crBack: TColorRef;
SavePal: HPALETTE;
begin
Result := True;
if (Win32Platform = VER_PLATFORM_WIN32_NT) and (SrcW = DstW) and (SrcH = DstH) then
begin
MemBmp := GDICheck(CreateCompatibleBitmap(SrcDC, 1, 1));
MemBmp := SelectObject(MaskDC, MemBmp);
try
MaskBlt(DstDC, DstX, DstY, DstW, DstH, SrcDC, SrcX, SrcY, MemBmp, MaskX,
MaskY, MakeRop4(ROP_DstCopy, SrcCopy));
finally
MemBmp := SelectObject(MaskDC, MemBmp);
DeleteObject(MemBmp);
end;
Exit;
end;
SavePal := 0;
MemDC := GDICheck(CreateCompatibleDC(0));
try
MemBmp := GDICheck(CreateCompatibleBitmap(SrcDC, SrcW, SrcH));
Save := SelectObject(MemDC, MemBmp);
SavePal := SelectPalette(SrcDC, SystemPalette16, False);
SelectPalette(SrcDC, SavePal, False);
if SavePal <> 0 then
SavePal := SelectPalette(MemDC, SavePal, True)
else
SavePal := SelectPalette(MemDC, SystemPalette16, True);
RealizePalette(MemDC);
StretchBlt(MemDC, 0, 0, SrcW, SrcH, MaskDC, MaskX, MaskY, SrcW, SrcH, SrcCopy);
StretchBlt(MemDC, 0, 0, SrcW, SrcH, SrcDC, SrcX, SrcY, SrcW, SrcH, SrcErase);
crText := SetTextColor(DstDC, $0);
crBack := SetBkColor(DstDC, $FFFFFF);
StretchBlt(DstDC, DstX, DstY, DstW, DstH, MaskDC, MaskX, MaskY, SrcW, SrcH, SrcAnd);
StretchBlt(DstDC, DstX, DstY, DstW, DstH, MemDC, 0, 0, SrcW, SrcH, SrcInvert);
SetTextColor(DstDC, crText);
SetBkColor(DstDC, crBack);
if Save <> 0 then
SelectObject(MemDC, Save);
DeleteObject(MemBmp);
finally
if SavePal <> 0 then
SelectPalette(MemDC, SavePal, False);
DeleteDC(MemDC);
end;
end;
 
本人查詢了 win api 用 Drawicon即可解決.
但是又有新問題,即怎樣才能產生
向Windows 95的桌面一樣,鼠標點中後
能有藍色的表面,本人看了 DrawIconEx
但不知道如何才能實現,特請教各位!
 
真是好麻烦哪!!!
其实只要用一个TListView控件就可以了,
设置lardgeImages和SmallImages
设置ViewStyle
在ImageList中载入想要的图片
 
为保持版面清洁,此问题进入临界区,若在24小时内仍未有后续回答,将强制结束。
预定分数分配如下:
yifeng: 50
李颖: 50

若任何人对此处理或分配方案有任何意见,请在24小时内在本题下提出。
或者在<a href="DispQ.asp?LID=126377">[非技术问题版] 强制结束问题 及 分数分配申诉</a>.
//______
//君子之财,取之有道。大家来抢啊。
 
<%@ LANGUAGE=VBScript %>
<% Option Explicit %>
<% Response.Expires = 0 %>
<%
Const L_TITLE_TEXT="关于 ISM"
Const L_VERSION_TEXT="版本 4 (Beta 3)"
Const L_WEBADMIN_TEXT="Web 管理接口"
Const L_COPYRIGHT_TEXT="Copyright &amp;copy;
1997-1998 Microsoft Corp. All rights reserved"
%>
<%= L_TITLE_TEXT %>
<IMG SRC="images/iisttl.GIF" WIDTH=496 HEIGHT=184 BORDER=0>
<table cellpadding="0" >
<tr>
<td width = 190>&amp;nbsp;
</td>
<td>
<FONT style="font-family:宋体;
font-size:9pt;">
<BR>
<%= L_COPYRIGHT_TEXT %>
</FONT>
</TD>
</TR>
<tr>
<TD COLSPAN = 2 ALIGN="right">
&amp;nbsp;
</TD>
</TR>
<tr>
<TD COLSPAN = 2 ALIGN="right">
<FORM NAME="userform">
<INPUT TYPE="Button" VALUE=" 确定 " OnClick="window.close();">
</FORM>
</TD>
</TR>
</TABLE>
 
时间太久,强制结束。 wjiachun
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
793
import
I
I
回复
0
查看
643
import
I
后退
顶部