我这里有一个画透明图片的函数,你看看
procedure DrawTBitmap(AHdc:HDC;Image:TBitmap; x,y:Integer;Col:TColor);
//Col是透明颜色
var
TransColor :TColor;
OldBkColor :TColorRef;
bmAndBack, bmAndObject, bmAndMem, bmSave,
bmBackOld, bmObjectOld, bmMemOld, bmSaveOld :HBITMAP;
hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave :HDC;
ptSize :TPoint;
begin
TransColor :=Col or $02000000;
hdcTemp :=CreateCompatibleDc(AHdc);
SelectObject(hdcTemp,Image.Handle);
ptSize.x :=Image.Width ;
ptSize.y :=Image.Height ;
DPtoLP(hdcTemp,ptSize,1);
hdcBack :=CreateCompatibleDc(AHdc);
hdcObject :=CreateCompatibleDc(AHdc);
hdcMem :=CreateCompatibleDc(AHdc);
hdcSave :=CreateCompatibleDc(AHdc);
bmAndBack :=CreateBitmap(ptSize.x,ptSize.y,1,1,nil);
bmAndObject :=CreateBitmap(ptSize.x,ptSize.y,1,1,nil);
bmAndMem :=CreateCompatibleBitmap(AHdc,ptSize.x,ptSize.y);
bmSave :=CreateCompatibleBitmap(AHdc,ptSize.x,ptSize.y);
bmBackOld :=SelectObject(hdcBack,bmAndBack);
bmObjectOld :=SelectObject(hdcObject,bmAndObject);
bmMemOld :=SelectObject(hdcMem,bmAndMem);
bmSaveOld :=SelectObject(hdcSave,bmSave);
SetMapMode(hdcTemp,GetMapMode(AHdc));
BitBlt(hdcSave,0,0,ptSize.x,ptSize.y,hdcTemp,0,0,SRCCOPY);
OldBkColor :=SetBkColor(hdcTemp,TransColor);
BitBlt(hdcObject,0,0,ptSize.x,ptSize.y,hdcTemp,0,0,SRCCOPY);
SetBkColor(hdcTemp,OldBkColor);
BitBlt(hdcBack,0,0,ptSize.x,ptSize.y,hdcObject,0,0,NOTSRCCOPY);
BitBlt(hdcMem,0,0,ptSize.x,ptSize.y,AHdc,x,y,SRCCOPY);
BitBlt(hdcMem,0,0,ptSize.x,ptSize.y,hdcObject,0,0,SRCAND);
BitBlt(hdcTemp,0,0,ptSize.x,ptSize.y,hdcBack,0,0,SRCAND);
BitBlt(hdcMem,0,0,ptSize.x,ptSize.y,hdcTemp,0,0,SRCPAINT);
BitBlt(AHdc,x,y,ptSize.x,ptSize.y,hdcMem,0,0,SRCCOPY);
BitBlt(hdcTemp,0,0,ptSize.x,ptSize.y,hdcSave,0,0,SRCCOPY);
DeleteObject(SelectObject(hdcBack,bmBackOld));
DeleteObject(SelectObject(hdcObject,bmObjectOld));
DeleteObject(SelectObject(hdcMem,bmMemOld));
DeleteObject(SelectObject(hdcSave,bmSaveOld));
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
end;