简体   繁体   English

DirectX C# SolidBrush 正在绘制白色

[英]DirectX C# SolidBrush is drawing white

I want to draw on a window.我想在窗户上画画。 To do that I created several brushes.为此,我创建了几个画笔。 For testing I used a normal red (255, 0, 0).为了测试,我使用了普通的红色 (255, 0, 0)。 Now I want to use more specific color like a 198, 17, 17 red.现在我想使用更具体的颜色,比如 198、17、17 红色。 I am creating the brush like this:我正在创建这样的画笔:

SolidColorBrush _redBrush = new SolidColorBrush(_device, new RawColor4(198, 17, 17, 1));

When I now draw in the window it is not red instead it is just white.当我现在在窗口中绘制时,它不是红色而是白色。 Could anyone please tell me what is wrong with this and how I can draw with the color I actually want?谁能告诉我这有什么问题以及我如何用我真正想要的颜色绘制?

Sorry if this is a really simple question but I am not very experienced with DirectX.对不起,如果这是一个非常简单的问题,但我对 DirectX 不是很有经验。 Also thanks for your help.也感谢您的帮助。

RawColor4需要介于 0 和 1 之间的浮点值。

Colors should be a percentage (in this scenario), so 1.0 is equivalent to 100%.颜色应该是一个百分比(在这种情况下),所以 1.0 相当于 100%。 When you tested 255,0,0 you saw red because you send 0 to green and blue channels and 255 or 25500% to the red channel, the same result could be achieved with (1,0,0).当您测试 255,0,0 时,您看到红色,因为您将 0 发送到绿色和蓝色通道,将 255 或 25500% 发送到红色通道,使用 (1,0,0) 可以获得相同的结果。

Change your values to percentage between 0 and 1 -> (198/255,17/255,17/255,1) The same apply for alpha channel so 1 is no transparency and 0 is full transparency.将您的值更改为 0 和 1 之间的百分比 -> (198/255,17/255,17/255,1) 同样适用于 alpha 通道,因此 1 表示不透明,0 表示完全透明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM