Delphi 6:字母混合在子图像和主画布之间起作用,但在子图像之间不起作用

发布于 2024-09-26 18:51:45 字数 1042 浏览 9 评论 0原文

我有一个 Delphi 6 应用程序,其中有一个 TBitmap 数组,每个 TBitmap 都包含一个图像(子图像),该图像是通过使用 clWhite 调用 FillRect() 创建的,以用白色淹没 TBitmap 的画布,然后调用 toTextOut()将一些文本打印到位图的画布上。

我有一个计时器,用于更新属于 TImage 组件的主 Canvas,每个时间间隔都会更新数组的内容,以反映对每个子图像 X、Y 坐标进行的更改,因为它们处于运动状态。首先,我将 FillRect() 与 clWhite 结合使用,用白色填充主画布。为了“打印”子图像,我只需迭代数组并调用 Alphablend() 将每个子图像“打印”到主画布上。每个子图像都有一个 Z 坐标,用于控制不透明度级别。 Z 坐标较高的子图像具有较低的 Alphablend() 值,使它们看起来比“近距离”的子图像更透明。

Alpha 混合对于每个单独的子图像都非常有效,并且具有较高坐标的子图像确实比具有较低 Z 坐标的子图像看起来更透明。但是,我遇到了 Z 空间中重叠的子图像的问题。重叠子图像之间的 Alpha 混合似乎不起作用。相反,重叠子图像“后面”的子图像被属于覆盖它的图像的白色背景遮挡。我想要的是两个子图像正确重叠,这样看起来就像两个文本字符串写在彼此之上。相反,我看到前面的文本字符串以及构成 TBitmap 画布的白色背景随处可见,从而擦除了它“后面”的文本字符串。

谁能告诉我为什么 alpha 混合在每个单独的子图像和主画布之间起作用,但在子图像之间不起作用?我只在时间上下文中说子图像之间,而不是作为对象,因为它们在打印时都应该成为主画布的一部分,并且我希望 alpha 混合能够正确地混合它们,但这并没有发生。

几乎就好像子图像之间的“白色”没有被视为与子图像之间的“白色”和属于主画布的“白色”相同。

后续:为了响应 Andreas 评论,我将所有子图像 TBitmap 的 PixelFormat 设置为 pf32bit。现在,阿尔法混合正在子图像“之间”进行。不幸的是,子图像的白色区域没有被视为透明颜色。相反,顶部子图像的白色背景与属于底层子图像的文本进行 Alpha 混合,在顶部子图像周围创建浅灰色框架,就像被涂抹一样。为了获得我想要的效果,我需要完全忽略子图像的白色背景。

I have a Delphi 6 application where I have an array of TBitmaps each containing an image (sub-image) that was created by making a call to FillRect() with clWhite to flood the TBitmap's Canvas with white, followed by a call toTextOut() to print some text to the Bitmap's Canvas.

I have a timer that updates the main Canvas, which belongs to a TImage component, with the contents of the array every Interval to reflect changes made to each sub-images X, Y coordinates since they are in motion. First I use FillRect() with clWhite to flood the main Canvas with white. To "print" the sub-images I simply iterate the array and call Alphablend() to "print" each sub-image on to the main Canvas. Each sub-image has a Z coordinate that is used to control the level of opacity. Sub-images with higher Z coordinates have a lower Alphablend() value to make them appear more transparent than those that are "up close".

The alpha-blending works great with each individual sub-image and those that have higher coordinates do indeed appear to be more transparent than those with lower Z coordinates. However, I'm having a problem with sub-images that overlap in Z space. Alpha-blending between overlapping sub-images does not appear to work. Instead, the sub-image "behind" the overlapping sub-image is occluded by the white background belonging to the image that overlays it. What I want is for the two sub-images to overlap properly so it looks like two text strings are written on top of each other. Instead I see the front text string and everywhere the white background that comprises it's TBitmap's Canvas exists, wiping out the text string "behind" it.

Can anyone tell me why alpha-blending is working between each individual sub-image and the main Canvas, but not between sub-images? I say between sub-images only in a temporal context and not as objects because they should all become part of the main Canvas as they print and I would expect alpha-blend to blend them properly, which is not happening.

It's almost as if the "white" between sub-images is not being treated the same as the "white" between a sub-image and the "white" belonging to the main Canvas.

FOLLOW-UP: In response to Andreas comment I set the PixelFormat of all sub-image TBitmap's to pf32bit. Now alpha-blending is taking place "between" sub-images. Unfortunately, the the sub-image's white areas are not being treated as a Transparent color. Instead the white background of the sub-image that is on top is being alpha-blended with the text belonging to the underlying sub-image creating a light gray frame around the sub-image on top as if it was smeared. To get the effect I want I need the white background of a sub-image to be completely ignored.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷月断魂刀 2024-10-03 18:51:45

如果您想使用 Alphablending 显示一些图像,请尝试使用 Graphics32 库。
在这里,您将找到一个组件“ImgView32”。有了这个,您可以轻松地显示具有任何位置和 alpbablend 值的任何类型的位图。您必须使用 TBitmapLayer 并对其进行绘图。

ImgView1:TImgView32;
a:array of TBitmapLayer;

procedure TForm1.FormCreate(Sender: TObject);
  var i:integer;

  begin
    ImgView1.Layers.Clear;
    SetLength (a,10);
    for i:=0 to High (a) do
      begin
        a[i]:=TBitmapLayer.Create(ImgView1.Layers);
        a[i].Location:=FloatRect(0,0,ImgView1.Width,ImgView1.Height);
        a[i].Scaled:=false;
        a[i].Bitmap.DrawMode:=dmOpaque;
        a[i].Bitmap.MasterAlpha:=255;
      end;
  end;

procedure TForm1.FormDestroy(Sender: TObject);
  begin
    ImgView1.Layers.Clear;
  end;

procedure Form1.DrawTextToLayer(Layer:TBitmapLayer;Text:string;X,Y:integer);
var I:TImage32;

begin
  I:=TImage32.Create(Form1);
  I.Width:=ImgView1.Width;
  I.Height:=ImgView1.Height;
  I.SetupBitmap;
  I.Bitmap.DrawMode:=dmBlend;
  I.Bitmap.Font.Size:=20;
  I.Bitmap.Font.Name:='Arial';
  I.Bitmap.Font.Style:=[fsBold];
  I.Bitmap.RenderText(x,Y,Text,2,clBlack32);
  Layer.Bitmap.Assign(I.Bitmap);
  I.Free        
end;

procedure TForm1.Button1Click(Sender: TObject);
   begin
     DrawTextToLayer(a[0],'Testing 1',10,10);
     DrawTextToLayer(a[1],'Testing 2',20,20);
     a[0].Bitmap.MasterAlpha:=255;
     a[1].Bitmap.MasterAlpha:=100;
   end;

If you would like to show some images with Alphablending, try to use the Graphics32 library.
In this, you will find a component "ImgView32". With this one, you can easily show any kind of bitmaps with any position and alpbablend value. You have to use TBitmapLayer and make your drawings to them.

ImgView1:TImgView32;
a:array of TBitmapLayer;

procedure TForm1.FormCreate(Sender: TObject);
  var i:integer;

  begin
    ImgView1.Layers.Clear;
    SetLength (a,10);
    for i:=0 to High (a) do
      begin
        a[i]:=TBitmapLayer.Create(ImgView1.Layers);
        a[i].Location:=FloatRect(0,0,ImgView1.Width,ImgView1.Height);
        a[i].Scaled:=false;
        a[i].Bitmap.DrawMode:=dmOpaque;
        a[i].Bitmap.MasterAlpha:=255;
      end;
  end;

procedure TForm1.FormDestroy(Sender: TObject);
  begin
    ImgView1.Layers.Clear;
  end;

procedure Form1.DrawTextToLayer(Layer:TBitmapLayer;Text:string;X,Y:integer);
var I:TImage32;

begin
  I:=TImage32.Create(Form1);
  I.Width:=ImgView1.Width;
  I.Height:=ImgView1.Height;
  I.SetupBitmap;
  I.Bitmap.DrawMode:=dmBlend;
  I.Bitmap.Font.Size:=20;
  I.Bitmap.Font.Name:='Arial';
  I.Bitmap.Font.Style:=[fsBold];
  I.Bitmap.RenderText(x,Y,Text,2,clBlack32);
  Layer.Bitmap.Assign(I.Bitmap);
  I.Free        
end;

procedure TForm1.Button1Click(Sender: TObject);
   begin
     DrawTextToLayer(a[0],'Testing 1',10,10);
     DrawTextToLayer(a[1],'Testing 2',20,20);
     a[0].Bitmap.MasterAlpha:=255;
     a[1].Bitmap.MasterAlpha:=100;
   end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文