delphi中怎么给图片加水印(两图片合成) ( 积分: 100 )

  • 主题发起人 主题发起人 ashow07
  • 开始时间 开始时间
A

ashow07

Unregistered / Unconfirmed
GUEST, unregistred user!
底部为一bmp图片,上面是bmp或gif图片,上面的图片设成半透明

希望能给详细代码
 
用两个IMAGE,上面那个Image的TransParent设置为True就可以了。
 
在原图上在加一张小图,半透明
procedure BlendBmp(BkGround,FrGround: TBitmap;Left,Top,Alpha,TransR,TransG,TransB: Integer);
var
X,Y: Integer;
PB,PF: PbyteArray;
R1,R2,G1,G2,B1,B2: Integer;
begin
BkGround.PixelFormat:=pf24bit;
FrGround.PixelFormat:=pf24bit;
for Y:=Top to BkGround.Height - 1 do
begin
if Y - Top > FrGround.Height - 1 then
Break;
PB:= BkGround.ScanLine[Y];
PF:= FrGround.ScanLine[Y-Top];
for X:=Left to BkGround.Width - 1 do
begin
if X - Left > FrGround.Width - 1 then
Continue;
B1:=PB[X * 3];
G1:=PB[X * 3 + 1];
R1:=PB[X *3 + 2];
B2:=PF[(X - left) * 3];
G2:=PF[(X - left) * 3 + 1];
R2:=PF[(X - left) * 3 + 2];
if(B2=TransB) and (G2 = TransG) and (R2 = TransR) then
Continue;
PB[X * 3]:=(B2 * Alpha + B1 * (255 - Alpha)) div 255;
PB[X * 3 + 1] :=(G2 * Alpha + G1 * (255 - Alpha)) div 255;
PB[X * 3 + 2] :=(R2 * Alpha + R1 * (255 - Alpha)) div 255;
end;
end;
end;
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=826084
 
上面给的代码在透明时颜色会变,比如是个红色的,合并了之后就是是红色了,成了黄色
 
procedure AddBmpSy(bmp1, bmp2: TBitmap; var bmp3: TBitmap);
var
i,j,it,jt:integer;
pcolor1,pcolor2:Tcolor;
begin
it:=bmp1.Width-bmp2.Width-6;
jt:=bmp1.Height-bmp2.Height-6;
bmp3.Width:=bmp1.Width;
bmp3.Height:=bmp1.Height;
for i:=0 to bmp1.Width-1 do
begin
for j:=0 to bmp1.Height-1 do
begin
bmp3.Canvas.Pixels[i,j]:=bmp1.Canvas.Pixels[i,j];
end;
end;
for i:=it to bmp2.Width+it-1 do
begin
for j:=jt to bmp2.Height+jt-1 do
begin
pcolor1:=bmp2.Canvas.Pixels[i-it,j-jt];
pcolor2:=bmp1.Canvas.Pixels[i,j];
if (GetRValue(pcolor1)>254) and (GetGValue(pcolor1)>254) and (GetBValue(pcolor1)>254) then
bmp3.Canvas.Pixels[i,j]:=pcolor2
else
bmp3.Canvas.Pixels[i,j]:=pcolor1
end;
end;

end;
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部