S
shaoye9604
Unregistered / Unconfirmed
GUEST, unregistred user!
两张图片透明叠加代码优化。
下面是我写的函数,速度慢了点,想用ScanLine来改写,但一直没写出来,请高手出手
相助!
Imag,BmpFileName:放置两张图片
XPos,YPos:叠加的位置
V:透明程序
procedure TransImage(Image: TImage; BmpFileName: string; XPos, YPos: Integer; V: Integer);
var
TempBmp : TBitmap;
hBmp, wBmp : Integer;
h, w : Integer;
r1, g1, b1, r2, g2, b2 : Byte;
begin
TempBmp := Tbitmap.Create;
TempBmp.PixelFormat := pf24bit;
TempBmp.LoadFromFile(BmpFileName);
hBmp := TempBmp.Height;
wBmp := TempBmp.Width;
for w := 0 to wBmp - 1 do
for h := 0 to hBmp - 1 do
begin
r1 := GetRValue(TempBmp.Canvas.Pixels[w, h]);
g1 := GetGValue(TempBmp.Canvas.Pixels[w, h]);
b1 := GetBValue(TempBmp.Canvas.Pixels[w, h]);
r2 := GetRValue(Image.Canvas.Pixels[XPos + w, YPos + h]);
g2 := GetGValue(Image.Canvas.Pixels[XPos + w, YPos + h]);
b2 := GetBValue(Image.Canvas.Pixels[XPos + w, YPos + h]);
Image.Canvas.Pixels[XPos + w, YPos + h] := RGB((R1 * V div 255) + (R2 * (255 - V) div 255), (G1 * V div 255) + (G2 * (255 - V) div 255), (B1 * V div 255) + (B2 * (255 - V) div 255));
end;
Tempbmp.Free;
end;
下面是我写的函数,速度慢了点,想用ScanLine来改写,但一直没写出来,请高手出手
相助!
Imag,BmpFileName:放置两张图片
XPos,YPos:叠加的位置
V:透明程序
procedure TransImage(Image: TImage; BmpFileName: string; XPos, YPos: Integer; V: Integer);
var
TempBmp : TBitmap;
hBmp, wBmp : Integer;
h, w : Integer;
r1, g1, b1, r2, g2, b2 : Byte;
begin
TempBmp := Tbitmap.Create;
TempBmp.PixelFormat := pf24bit;
TempBmp.LoadFromFile(BmpFileName);
hBmp := TempBmp.Height;
wBmp := TempBmp.Width;
for w := 0 to wBmp - 1 do
for h := 0 to hBmp - 1 do
begin
r1 := GetRValue(TempBmp.Canvas.Pixels[w, h]);
g1 := GetGValue(TempBmp.Canvas.Pixels[w, h]);
b1 := GetBValue(TempBmp.Canvas.Pixels[w, h]);
r2 := GetRValue(Image.Canvas.Pixels[XPos + w, YPos + h]);
g2 := GetGValue(Image.Canvas.Pixels[XPos + w, YPos + h]);
b2 := GetBValue(Image.Canvas.Pixels[XPos + w, YPos + h]);
Image.Canvas.Pixels[XPos + w, YPos + h] := RGB((R1 * V div 255) + (R2 * (255 - V) div 255), (G1 * V div 255) + (G2 * (255 - V) div 255), (B1 * V div 255) + (B2 * (255 - V) div 255));
end;
Tempbmp.Free;
end;