首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

图片附加算法

2013-01-08 
图片叠加算法procedure TCopyScreent.AlphalBmp(BackBmp, foreBmp: TBitmapAlphal: Byte Rect : TRect)

图片叠加算法


procedure TCopyScreent.AlphalBmp(BackBmp, foreBmp: TBitmap;  Alphal: Byte ; Rect : TRect);
var R1 , G1 , B1 , R2 , G2 , B2 : Byte;
    X , Y : Integer;
    PB , PF : PByteArray;
begin
  BackBmp.PixelFormat := pf24bit;
  foreBmp.PixelFormat := pf24bit;
  for Y := 0 to BackBmp.Height-1 do
  begin
    PB := BackBmp.ScanLine[Y];
    PF := foreBmp.ScanLine[Y] ;

    X:=0;
    while X<=(BackBmp.Width-1)*3 do
    begin
      Inc(X,3) ;
      if (X>=Rect.Left*3) and (X<=Rect.Right*3) and (Y>=Rect.Top) and (Y<=Rect.Bottom) then
      begin
        Continue;
      end
      else
      begin
        B1 := PB[X]; G1 := PB[X+1];  R1 := PB[X+2];
        B2 := PF[X]; G2 := PF[X+1];  R2 := PF[X+2];
        PB[X] := Trunc((B1*(255-Alphal)+B2*Alphal)/255);
        PB[X+1] := Trunc((G1*(255-Alphal)+G2*Alphal)/255);
        PB[X+2] := Trunc((R1*(255-Alphal)+R2*Alphal)/255);
      end;

    end;
  end;

end;

将前景色与背景图片叠加, 现在的这种方法速度感觉太慢了
不知道还有没有其它比较高效的算法做到上面的功能
[解决办法]
可找maozefa
[解决办法]
AlphaBlend

[解决办法]
Trunc((B1*(255-Alphal)+B2*Alphal)/255);
不建议这么写

用移位操作 
((B1*(255-Alphal)+B2*Alphal) shr 8);

热点排行