呵呵,我这里也有一个,以前自己写的,用于在生成的卡片上盖章。
{
dest 是目标bitmap
source 是要附加到上边去的东西
destrect,是附加到什么区域去
srcRect 是截取原图片的某个区域
tcl 是透明色
}
procedure DrawTrans(var dest:TBitmap;destRect :TRECT;source:TBitmap;srcRECT :TRECT;tCl:TColor);
var
tb1,tb2:TBitmap;
R,G,B:Byte;
i,x,y :Integer;
cs,cd
ByteArray;
begin
{初始化}
R:=GetRValue(tcl);
G:=GetGValue(tcl);
B:=getBvalue(tcl);
tb1:=Tbitmap.Create ;
tb2:=Tbitmap.Create ;
tb1.HandleType :=bmDIB;
tb2.HandleType :=bmDIB;
tb1.PixelFormat :=pf24bit;
tb2.PixelFormat :=pf24bit;
{第一步: 变大小,将source中srcRect部分拷贝出来并缩放为 destREct大小
这里为了减小失真采取两步,后截取,后变大小,);
这里有个坐标转换的问题 }
tb1.Width :=srcrect.Right -srcrect.Left;
tb1.Height :=srcrect.Bottom -srcrect.Top;
tb1.canvas.CopyRect(rect(0,0,srcrect.Right -srcrect.Left ,srcrect.Bottom -srcrect.Top),source.Canvas ,srcRect);
tb2.Height :=dest.Height ;
tb2.Width :=dest.Width ;
tb2.Canvas.StretchDraw(destrect,tb1);
tb1.FreeImage ;
tb1.Assign(dest);
{第二步: 复制费透明部分}
tb2.Width :=tb1.Width ;
tb2.Height :=tb1.Height ;
for Y:=0 to tb2.height -1 do
begin
cd:=tb1.ScanLine[Y];
cs:=tb2.ScanLine[Y];
for X:=0 to tb2.Width -1 do
if not((cs[X*3]=B)and(cs[X*3+1]=G)and(cs[X*3+2]=R)) then
for I:=0 to 2 do cd[x*3+I]:=cs[x*3+I];
end;
dest.Assign(tb1);
tb1.free;
tb2.free;
end;