图片淡入淡出

function IntToByte(i: Integer): Byte;
begin
  if i > 255 then
    Result := 255
  else if i < 0 then
    Result := 0
  else
    Result := i;
end;

procedure BmpAlphaBlend(var Bmp: TBitMap; dBmp, sBmp: TBitmap; Pos: TPoint; Alpha: integer; TranColor: TColor = -1);
type
  tagRGBTRIPLE = packed record
    rgbtBlue: Byte;
    rgbtGreen: Byte;
    rgbtRed: Byte;
  end;
  TRGBTriple = tagRGBTRIPLE;
  PRGBTripleArray = ^TRGBTripleArray;
  TRGBTripleArray = array[0..32767] of TRGBTriple;
  function GetSLColor(pRGB: TRGBTriple): TColor;
  begin
    Result := RGB(pRGB.rgbtRed, pRGB.rgbtGreen, pRGB.rgbtBlue);
  end;
var
  p0, p1, p2: PRGBTripleArray;
  r, g, b, p, x, y: Integer;
begin
  sBmp.PixelFormat := pf24bit;
  dBmp.PixelFormat := pf24bit;
  if TranColor = -1 then
    TranColor := sBmp.Canvas.Pixels[0, 0];
  for y := 0 to sBmp.Height - 1 do
    if (y + Pos.y >= 0) and (y + Pos.Y < dBmp.Height) then
    begin
      p0 := dBmp.ScanLine[y + Pos.y];
      p1 := sBmp.ScanLine[y];
      p2 := Bmp.ScanLine[y + Pos.y];

      for x := 0 to sBmp.Width - 1 do
        if (x + pos.X >= 0) and (x + Pos.X < dBmp.Width) then
          if GetSLCOlor(p1[x]) <> TranColor then
          begin
            p2[x + pos.X].rgbtRed := IntToByte((p0[x + pos.X].rgbtRed * (100 - Alpha) +
              p1[x].rgbtRed * Alpha) div 100);

            p2[x + pos.X].rgbtGreen := IntToByte((p0[x + pos.X].rgbtGreen * (100 - Alpha) +
              p1[x].rgbtGreen * Alpha) div 100);

            p2[x + pos.X].rgbtBlue := IntToByte((p0[x + pos.X].rgbtBlue * (100 - Alpha) +
              p1[x].rgbtBlue * Alpha) div 100);
          end;
    end;

end;


procedure TForm1.Button1Click(Sender: TObject);
var
  brBmp, srcBmp, temBmp: TBitmap;
  i: integer;
begin
//
  brBmp := TBitmap.Create;
  brBmp.LoadFromFile('c:/a.bmp');
  brBmp.PixelFormat := pf24bit;
  temBmp := TBitmap.Create;
  temBmp.Assign(brBmp);

  srcBmp := TBitmap.Create;
  srcBmp.LoadFromFile('c:/b.bmp');
  srcBmp.PixelFormat := pf24bit;
  for i := 0 to 100 do
  begin
    BmpAlphaBlend(
      temBmp,
      brBmp, //背景图(大图,也是结果图)
      srcBmp, //需要合成的小图
      Point(0, 0), //画小图的坐标
      i, //半透明度,最大100
      -1 //需要透明的颜色(用于不规则图形,-1就表示以0,0位置的颜色为透明色)
      );

    canvas.Draw(0, 0, temBmp);
  end;
  brBmp.Free;
  temBmp.Free;
  srcBmp.Free;


end;

picshow组件
http://www.delphiarea.com/products/


SaveFrom: about:blank
SaveTime: 2006-8-21 9:42:56
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值