如何解决双层Image闪烁问题?

zjsheng 2006-08-02 09:25:48

一个面积小的Image在一个面积大的Image之上

通过拖动一个TrackBar在其OnChange事件中

对面积小的Image进行透明度处理时闪烁挺严重的

部分代码如下:

procedure TFormMain.TBAlphaChange(Sender: TObject);
var
BF: BLENDFUNCTION;
bmp: TBitmap;
begin
if (Image2.Picture.Bitmap.Empty = false) and (CBAlpha.Checked) then
begin
BF.BlendOp := AC_SRC_OVER;
BF.BlendFlags := 0;
BF.SourceConstantAlpha := Round(255*TBAlpha.Position / 100);
BF.AlphaFormat := 0;
bmp := TBitmap.Create;
bmp.Assign(Image2.Picture.Bitmap);
Image2.Picture.Assign(nil);
Windows.AlphaBlend(Image2.Canvas.Handle, 0,0,Image2.Width,Image2.Height,Bmp.Canvas.Handle, 0,0,Image2.Width, Image2.Height,BF);
bmp.Free;
end;
end;
...全文
407 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
数字蛋糕 2006-11-12
  • 打赏
  • 举报
回复
Image.Parent.DoubleBuffered := True;
GARNETT2183 2006-10-09
  • 打赏
  • 举报
回复
试试开又缓冲。。。
DoubleBuffer := True;
xzhifei 2006-10-09
  • 打赏
  • 举报
回复
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 dBmp: TBitMap; 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: 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];
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
p0[x + pos.X].rgbtRed := IntToByte((p0[x + pos.X].rgbtRed * (100 - Alpha) +
p1[x].rgbtRed * Alpha) div 100);

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

p0[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: TBitmap;
begin
//
brBmp := TBitmap.Create;
brBmp.LoadFromFile('c:\a.bmp');
brBmp.PixelFormat := pf24bit;

srcBmp := TBitmap.Create;
srcBmp.LoadFromFile('c:\b.bmp');
srcBmp.PixelFormat := pf24bit;

BmpAlphaBlend(
brBmp, //背景图(大图,也是结果图)
srcBmp, //需要合成的小图
Point(60, 60), //画小图的坐标
100, //半透明度
-1//需要透明的颜色(用于不规则图形,-1就表示以0,0位置的颜色为透明色)
);

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



------------------------------------------------------- 本回复由大傻的破玩意儿【CSDN's forum Explorer】完成! 大傻的破玩意儿,今天你用了木有 !! 软件功能强大,速度超快!!支持中... 软件下载地址:http://CoolSlob.ys168.com
zhaogang 2006-10-04
  • 打赏
  • 举报
回复
同意楼上的
因为我也刚刚做过类似的组件
gobiz 2006-09-30
  • 打赏
  • 举报
回复
DoubleBuffer := True;
zjsheng 2006-08-02
  • 打赏
  • 举报
回复

D7 环境

我不是指每次透明处理都会

而是在拖动TrackBar时实时处理并显示小的Image的透明效果时有闪烁现象
pyxyu 2006-08-02
  • 打赏
  • 举报
回复
你是在delphi6上编译的吧,在delphi7就不会出现这种问题了!

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧