5

在 Delphi XE2 中,我有一个带有图像缩略图的 ListView。当我单击其中一个缩略图时,我希望 ListView 被一个深色的半透明图层覆盖,并将单击的图像放大到该图层的顶部。

由于不可能将 TImage 放在 ListView 的顶部,因此我尝试使用另一种具有 AlphaBlend 128 透明度的表格作为图层。然而,这个 AlphaBlend 形式也使得它上面的 TImage 是 Alpha 透明的。

所以目标似乎是使图层形成 AlphaBlend 透明而不是其上的图像。如何做到这一点?


2012 年 8 月 7 日编辑:

解决了!!感谢 Remy Lebeau,他给了我决定性的暗示来培养形象。我从 TMS 中找到了 TW7Image,这是我所知道的唯一具有 Opacity(即 AlphaBlend)属性的图像类型。我使用了这个程序:

在 W7Image 中,在 Picture 属性中加载一个黑色图像,将 Opacity 设置为 192 并设置 Stretch 模式。

将其他图像设置为中心、比例等,然后:

// In this order (!):
// 1.
imgSemiTransparentBlackLayer.Parent := MyListView;
imgSemiTransparentBlackLayer.Align := alClient;
// 2.
imgTop.Picture.LoadFromFile('MyPicture.png');
imgTop.Parent := MyListView;
imgTop.Align := alClient;
4

1 回答 1

4

The TForm.AlphaBlend property applies to the entire TForm as a whole. What you need is per-pixel alpha-blending instead, which TForm does not natively support. You could call UpdateLayeredWindow() to implement per-pixel alpha, but that may conflict with the VCL's use of SetLayeredWindowAttributes().

For a purely VCL solution, you could try using two TForm objects. Have one TForm contain just the TImage and no background, then have a second TForm lay on top of it, where the second TForm has both its TransparentColor and AlphaBlend properties enabled, has a square of the TransparenColorValue that is the same dimensions as the TImage, and has a dark background color that gets alpha-blended with whatever is underneath it.

An alternative solution would be to use the Win32 API CreateWindowEx() function directly to create the image window, then you can use UpdateLayeredWindow() on it. That requires you to create an in-memory bitmap to back the window drawing, so you can draw your image directly on to that bitmap, rather than using a TImage component. Then you just give it a dark background and specify a per-pixel alpha for the bitmap pixels surrounding the image pixels.

BTW, you can put a TImage on top of a TListView, if you set the TListView as the TImage.Parent. You just won't be able to alpha-blend the TImage, that's all.

于 2012-08-07T02:05:51.740 回答