Delphi 6:如何使用具有 Alpha 通道的 TextOut 创建位图?

发布于 2024-09-26 14:24:51 字数 746 浏览 11 评论 0原文

我将描述我的总体目标,以防我提出的问题不是获得我正在寻找的答案的最佳形式。我有一个围绕 X 轴旋转的单词球体或“单词球”。当单词旋转到后面时(Z坐标从-1到1,从前到后),我打算更改每个单词的大小和不透明度,以便“前面”中的单词100%不透明且全尺寸,并且单词后面较小且有些透明。我更愿意使用直接的 Delphi 代码来完成此操作,并避免使用 Direct3D 等。我已经有了可以正常工作的旋转代码。我只需要实现我的基于 Z 坐标的感知着色想法。

当我创建单词球时,我为每个单词动态创建一个 TImage 组件。我使用 TCanvas.TextOut() 方法以居中方式将单词“打印”到 TImage 位图。我打算使用 BitBlt 将该位图复制到保存单词球的主 Canvas 中的正确位置,因为 BitBlt 速度很快,并且可以动态调整位图大小,满足我的感知着色操作的要求之一。

但我不知道促进 Alpha 混合的最佳方法。我知道 Windows 有 AlphaBlend() 调用,而且使用起来似乎相当简单。但我需要知道如何创建一个位图,该位图是具有 Alpha 通道的每个字 TImage 组件的副本。请注意,在我的例子中,整个位图的 Alpha 通道将具有统一的值,因为我希望根据 Z 坐标将不透明度均匀地应用于整个单词。

动态创建的 TImage 组件(带有使用 TCanvas.TextOut() 制作的位图)是否有 Alpha 通道?如果没有,我如何创建一个,或者实时创建一个 TImage 位图的副本,该副本具有要传递给 AlphaBlend() 调用的 Alpha 通道?如果有更好的方法来完成这一切,请告诉我。

I'll describe my overall goal in case the question I asked isn't in the best form to get the answer I'm looking for. I have a sphere of words or "word ball" that spins around the X axis. As words spin to the back (Z coordinate goes from -1 to 1, front to back), I intend to change the size and the opacity of each word so that words in "front" are 100% opaque and full-sized and words in back are smaller and somewhat transparent. I would prefer to do this with straight Delphi code and avoid things like Direct3D, etc. I already have the rotation code working fine. I just need to implement my Z coordinate based perceptual shading idea.

When I create the word ball I dynamically create a TImage component for each word. I "print" the word to the TImage bitmap using the TCanvas.TextOut() method in a centered manner. I intend to use BitBlt to copy that bitmap to the correct location in the main Canvas that holds the word ball, because BitBlt is fast and can resize bitmaps on-the-fly, meeting one of the requirements for my perceptual shading operation.

But I don't know the best way to facilitate the Alpha blending. I know that Windows has the AlphaBlend() call and it seems fairly straightforward to use. But I would need to know how to create a bitmap that is a copy of the per-word TImage component that has an alpha channel. Note, in my case the entire bitmap will have a uniform value for the alpha channel since I want the opacity to be applied uniformly to the entire word, based on it's Z coordinate.

Does a dynamically created TImage component with a bitmap made by using TCanvas.TextOut() have an Alpha channel? If not, how do I create one, or create a copy of a TImage bitmap in real time that does have an Alpha channel to be passed to the AlphaBlend() call? If there's a better way to do all this just let me know.

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

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

发布评论

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

评论(2

无声静候 2024-10-03 14:24:51

文档说:

BLENDFUNCTION 的 SourceConstantaAlpha 成员指定要在整个源位图上使用的 alpha 透明度值。 SourceConstantaAlpha 值与任何每像素 alpha 值相结合。如果 SourceConstantaAlpha 为 0,则假定图像是透明的。当您只想使用每像素 Alpha 值时,将 SourceConstantaAlpha 值设置为 255(这表示图像不透明)。

所以我想如果您只想要整个图像恒定的透明度,您的图像不必采用任何特殊格式。

另一方面,我认为这不是你想要的。想象一下一个矩形区域的文本与另一个区域重叠:虽然矩形的某些部分可能没有文本,但它们仍然会以半透明的白色或任何您作为背景、颜色的颜色绘制。

The documentation says:

The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantaAlpha value is combined with any per-pixel alpha values. If SourceConstantaAlpha is 0, it is assumed that the image is transparent. Set the SourceConstantaAlpha value to 255 (which indicates that the image is opaque) when you only want to use per-pixel alpha values.

So I guess your image doesn't have to be in any special format if you just want a whole image constant transparency.

On the other hand, I don't think that's what you want. Just imagine one rectangular area with text overlapping with another: although some parts of the rectangle might not have text, they'll still be drawn in a semi-transparent white, or whatever one you have as background, color.

可是我不能没有你 2024-10-03 14:24:51

我发现这个链接给出了如何在 Delphi 6 中进行 Alpha 混合的可靠示例,现在我可以使用它了:

http://www.delphi-central.com/tutorials/AlphaBlend.aspx

它与使用 BitBlt() 或 StretchBlt() 参数非常接近,除了最后一个参数是 alpha -混合结构并且非常容易理解。将其与上面“他自己”的评论结合起来,您就拥有了进行 Alpha 混合所需的一切。

I found this link that gives a solid example of how to do Alpha Blending in Delphi 6 and now I have it working:

http://www.delphi-central.com/tutorials/AlphaBlend.aspx

It's very close to using BitBlt() or StretchBlt() parameter-wise, except for the last parameter which is the alpha-blend structure and is very easy to understand. Combine that with the comment by "himself" above and you have all you need to do Alpha blending.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文