画布笔触和填充颜色

时间:2020-01-30 11:33:23

标签: javascript canvas

问题是笔触的不透明度低于填充的不透明度,我无法使笔触的颜色与填充的颜色具有相同的不透明度。

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeStyle = "rgba(255,0,0,1)";
ctx.fillStyle = "rgba(255,0,0,1)";
ctx.strokeRect(20, 20, 25, 25);
ctx.fillRect(20, 50, 25, 25);
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
    Your browser does not support the HTML5 canvas tag.</canvas>

如果将fillStyle的不透明度设置为0.5,则它们将相同,但是我们不能提高笔触的不透明度。

那么如何将笔触颜色设置为与填充颜色相同?

1 个答案:

答案 0 :(得分:4)

它们的颜色完全相同。问题是抗锯齿。

如果将笔划变宽,可以检查它是否看起来更黑。

   {
       provide: NGXS_PLUGINS,
       useFactory: myfunction,
       deps: [Store],
       multi: true
    }

它在笔画的中心部分将显示为红色,而在其边缘将显示为不饱和的红色。

遗憾的是,您可以控制它(即将其关闭),因为它取决于浏览器。

您可以在其他question中阅读有关它的更多信息(并寻找替代方法)。

对我来说更好的技巧是将画布平移半像素距离。

export function extendApplication(store: Store) {
  return function extendApplication(state, action, next) {
  if (state.user.loggedIn){

    if (getActionTypeFromInstance(action) !== LogoutUser.type) {

      here is where I want to set a timer and if no other actions
      occur before the timer expires I want to dispatch a logout action

      return next(state, action);
    }
  }else{
    return next(state, action);
  }}

建议使用herehere。我不能确定是否能在每个浏览器中达到预期的效果(我在Firefox上进行了测试)。

Pls check in below URL: 

https://codepen.io/minhdynasty/pen/ozvAPJ

It will close th pop up
ctx.lineWidth = 5;

相关问题