- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想绘制一个自定义的半透明光标,它是一个白色圆圈。我在 Windows 7 操作系统中使用 Delphi XE3。
我的代码在某种程度上可以正常工作。我可以设置 Alpha channel 并修改透明度,但颜色是银色/深灰色而不是白色。
当我运行调试时,我可以看到正在设置正确的白色 ($B4FFFFFF),其中 $B4 是 alpha 值。
我已经根据之前的 subject 调整了我的代码
type
pScanLineArray = ^TScanLineArray;
TScanLineArray= array [Word] of Cardinal;
procedure TForm1.Button1Click(Sender: TObject);
const CursorIdx = TCursor(-25); {arbitrary}
Mid = 64; {middle of cursor dimension (128)}
FPenSize = 50;
var IconInfo : TIconInfo;
X, Y: Integer;
AlphaCursor: HCURSOR;
ForG, BackG, Border: Cardinal;
Dist: Double;
LineP: pScanLineArray;
FCursorMaskBMP,FCursorColorBMP: TBitmap;
begin
{Create Bitmaps}
FCursorMaskBMP:= TBitMap.Create;
FCursorMaskBMP.PixelFormat:= pf32bit;
FCursorMaskBMP.SetSize(128, 128);
FCursorColorBMP:= TBitMap.Create;
FCursorColorBMP.PixelFormat:= pf32bit;
FCursorColorBMP.SetSize(128, 128);
{Fill the AND mask. In this case, content ignored by windows}
FCursorMaskBMP.Monochrome := True;
FCursorMaskBMP.Canvas.Brush.Color := clWhite;
FCursorMaskBMP.Canvas.FillRect(FCursorMaskBMP.Canvas.ClipRect);
{Set all the colors for the cursor}
ForG:= $B4FFFFFF; {semi-transarent white - for inside of circle}
BackG:= $00000000; {Full transparent - for outside of circle}
Border:= $FF000000; {non-transparent black for border}
{Fill the bitmap}
for Y := 0 to (FCursorColorBMP.Height - 1) do
begin
LineP := FCursorColorBMP.ScanLine[Y];
for X := 0 to (FCursorColorBMP.Width - 1)do
begin
Dist:= SQRT(Power(Y-Mid,2)+Power(X-Mid,2)); {Distance from middle of circle}
if Dist<FPenSize then {Within circle - apply forground trasparent color}
LineP^[X] := ForG
else
if (Dist>=FPenSize) and (Dist<FPenSize+1) then
LineP^[X] := Border {This is the border - apply opaque color of border}
else
LineP^[X] := BackG; {Outside circle - apply fully transparent color }
end;
end;
FCursorColorBMP.AlphaFormat := afDefined; {does not seem to have any effect ?}
with IconInfo do
begin
fIcon := false;
xHotspot := Mid;
yHotspot := Mid;
hbmMask := FCursorMaskBMP.Handle;
hbmColor := FCursorColorBMP.Handle;
end;
AlphaCursor:=CreateIconIndirect(IconInfo);
Win32Check(Bool(AlphaCursor)); {My guess is that this is some error checking ?}
Screen.Cursors[CursorIdx] := AlphaCursor;
Screen.Cursor := CursorIdx;
end;
注意:要编译上述内容,必须将单元“Math”添加到“uses”子句中
在这种特殊情况下,光标的最终颜色(图像白色上方的部分)是 $xxCACACA
我还尝试了除白色之外的其他颜色。结果相似 - 颜色变得“变暗”
如果我将 Alpha channel 设置为不透明,那么我会按预期得到一个白色光标(但当然不再透明)。
我的猜测是,我看到的是光标白色混合两次的结果:
与黑色/深色背景的混合(也许是 AND 蒙版?)
与屏幕图像混合。
但这只是一个猜测,我不知道从这里该去哪里。有人可以帮忙吗?
<小时/>有关更新
FCursorColorBMP.AlphaFormat := afDefined;
当上面的行出现在代码中时,我得到以下结果
如果抓取颜色值(使用 MS Paint),光标与不同颜色重叠会产生这些值 (RGB):
white overlap: 164, 164, 164
Red overlap : 157, 97, 100
Green overlap: 89, 127, 89
Blue overlap : 89, 89, 164
如果我省略上述行或将其更改为
FCursorColorBMP.AlphaFormat := afIgnored;
然后我得到了这张图片
当我抓取颜色时,我得到以下值:
white overlap: 202, 202, 202
Red overlap : 197, 135, 138
Green overlap: 127, 165, 127
Blue overlap : 127, 127, 202
看到 Tom Brunberg 的回答后,我想我应该制作一个 exe 文件并在另一台机器上运行它。结果很好并且与汤姆的结果一致。
所以总而言之,Alphaformat应该设置为AfIgnored(或line omited),这在技术上解决了某些系统上的问题。
由于某种原因,我的系统仍然显示错误的颜色,但是!我的 Win7 实际上通过 Mac OS 上的 Parallels 运行 - 不知道这是否是奇怪行为的原因。
最佳答案
按原样应用代码时,我得到以下结果:
但是,如果我改变
FCursorColorBMP.AlphaFormat := afIgnored; {does not seem to have any effect ?}
我得到:
由于 afIgnored
是默认值,因此您可以简单地省略该行,正如 Sertac Akyuz 在他的评论中建议的那样。
如果您觉得白色太不透明,请减小 Alpha 值。
<小时/>编辑,更多信息:
虽然我没有找到任何相关文档,但我非常有信心 Windows 在渲染光标时使用 alpha 值,因此不应预先计算位图。为了支持我的想法,我用纯红色、绿色和深蓝色的几种颜色进行了以下检查:
Alpha 混合的一般公式是
output = alpha * foreground + (1-alpha) * background
并且它是针对红、绿、蓝分量分别计算的。
使用上面的白色覆盖层和 alpha 值(A:B4, R:FF, G:FF, B:FF)
覆盖的颜色分量
- red field (R:FF, G:0, B:0) becomes R:FF, G:B4, B:B4.
- green field (R:0, G:BF, B:0) becomes R:B4, G:EC, B:B4.
- blue field (R:0, G:0, B:7F) becomes R:B4, G:B4, B:D9.
以上值是使用图形编辑程序的“滴管”获取的。
这些值与使用计算得出的值相同
// Result color components
resR := a * fgR div $FF + ($FF - a) * bgR div $FF;
resG := a * fgG div $FF + ($FF - a) * bgG div $FF;
resB := a * fgB div $FF + ($FF - a) * bgB div $FF;
哪里
// overlay alpha
a := $B4;
// overlay color components
fgR := $FF;
fgG := $FF;
fgB := $FF;
和
// background color components for the red field
bgR := $FF;
bgG := $0;
bgB := $0;
// background color components for the green field
bgR := $0;
bgG := $BF;
bgB := $0;
// background color components for the dark blue field
bgR := $0;
bgG := $0;
bgB := $7F;
将新创建的位图的 bitmap.AlphaFormat
设置为 afDefined
或 afPremultiplied
时执行预计算(默认为 afIgnored
)。(参见Vcl.Graphics
中的过程TBitmap.SetAlphaFormat(Value: TAlphaFormat);
)
关于delphi - Delphi 中透明光标显示错误颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35995991/
我想禁用我的 UIButton,所以我调用: button.enabled = FALSE; 然而,这会使按钮变得透明,我可以看到它下面的元素。我不介意它改变颜色,我只是不希望它是透明的。 我尝试在
一个常规的 NSButton 如果被禁用,它似乎是透明的。 图像显示了一个样式为“push”的按钮 但是,我想禁用没有透明度的按钮。 我试图以编程方式将 alphaValue 设置为 1.0 但似乎
我正在尝试将Memoji从iPhone/Mac转换为具有透明背景的一系列png,以便我可以创建一个 Sprite 表。当按下空格键时,我可以清楚地看到它具有透明背景,但是在运行 ffmpeg -i s
我想创建一个具有部分透明背景的 View (舞台、窗口)。我有一张包含 Alpha channel 的图像 我在JavaFx中使用了这种场景,我必须将场景填充设置为空,并将根节点背景颜色设置为透明。我
我想创建一个具有部分透明背景的 View (舞台、窗口)。我有一张包含 Alpha channel 的图像 我在JavaFx中使用了这种场景,我必须将场景填充设置为空,并将根节点背景颜色设置为透明。我
我想将 JDesktopPane 设置为透明,并允许我单击下面的内容(例如桌面图标等)。内部框架应保持不透明,并且能够像当前一样在屏幕周围重新定位。有什么想法吗? package test1;
我知道我不是第一个提出此类问题的人,但我认为我的问题有点不同。 我在 MS Paint 上绘制了一个 png 图像,它是一个播放器,当我使用图形对象绘制图像时,我希望图像的背景是透明的。我尝试了一些带
我在 Mac 的 swift 项目中想使用单选按钮,但与我的背景颜色相同。如何将背景设置为不透明或更改背景颜色? 最佳答案 我找到了解决此问题的方法。将单选按钮的文本设置为“”,将 rb 添加到水平堆
我无法将我的相对布局设置为透明。我尝试了很多不同的方法,从类中自定义 View ,添加 android:background="@android:color/transparent"等。它们要么像下图
在 Storyboard中,我创建了一个 ![UINavigationController] 及其 Root View Controller UIViewcontroller。在工具栏中,我有一个分段
我必须让我的导航栏透明,我试过这段代码: self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIB
我注意到,如果我将 View 背景颜色设置为透明,则在 segue 过渡结束后背景颜色会变成黑色(我猜这是默认的“视口(viewport)”颜色)。 我可以改变吗?当然,我可以将颜色从透明更改为紫色,
嘿,有没有可能让滚动条“隐藏”,我不想使用 overflow-y: hidden就像背景:透明或类似的东西 最佳答案 Here您会找到有关如何仅使用 CSS 隐藏滚动条的说明。 在第二个example
默认情况下,背景显示为白色。是否可以通过任何方式将其背景颜色更改为透明..? (function() { var cx = '005519348941191855053:d0uziw7c
我正在尝试添加一个在 div 的左右边缘具有透明度/淡出的嵌入框阴影。我设法添加了一个普通的嵌入框阴影,但我不知道如何为边缘添加透明度。我该怎么做? 这是我正在努力实现的一个例子。 .contai
如何删除 周围的边框并使其背景透明? 最佳答案 试试这个: border: none; border-color: transparent; 关于html - 透明、无边框的文本输入,我们在Stac
是否可以使 JButton 透明(包括边框)而不是文本?我扩展了 swing 的 JButton 并覆盖了它: @Override public void paint(Graphics g) {
众所周知,要使QWidget/QOpenGLWidget半透明/透明,只需: widget->setAttribute(Qt::WA_TranslucentBackground) 但是,由于 QWin
我想知道如何在 Ubuntu 中为所有应用程序制作透明 Gnome 终端,我知道我们可以为桌面制作透明终端,而不是为所有应用程序制作透明终端。我用谷歌搜索了很多,但找不到任何解决方案。谁能告诉我该怎么
我想让 SWT Canvas 的背景透明,以便可以看到它后面的其他小部件。 我尝试将 alpha 设置为 0 并用矩形填充 Canvas ,并且还使用选项 SWT.NO_BACKGROUND 无济于事
我是一名优秀的程序员,十分优秀!