【问题标题】:set image insted of paint ball in javascript在javascript中设置图像而不是彩弹
【发布时间】:2014-07-18 17:38:16
【问题描述】:

我想设置图像而不是画球

我的代码如下

  ballPainter = {
      BALL_FILL_STYLE: 'rgb(255,0,50)',
      BALL_STROKE_STYLE: 'rgb()',

      paint: function (ball, context) { 
         var imageObj = new Image();

         context.save();

         context.shadowColor = undefined;
         context.lineWidth = 2;
         context.fillStyle = this.BALL_FILL_STYLE;
         context.strokeStyle = this.BALL_STROKE_STYLE;

         context.beginPath();
         context.arc(ball.left, ball.top,
                     ball.radius, -1, Math.PI*2, false);

         context.clip();
         context.fill();
         context.stroke();
         context.restore();
      }
    },

【问题讨论】:

  • 您需要在画布上绘制还是在页面上添加圆形元素(例如 div)?

标签: javascript


【解决方案1】:

您可能需要检查 http://www.w3schools.com/tags/canvas_drawimage.asp

我不确定您是否可以将图像裁剪为 cricle(也许图像具有透明背景)

*编辑显然你可以HTML5 Canvas - Fill circle with image

【讨论】:

  • 谢谢你能给我正确的代码...我真的需要
猜你喜欢
  • 1970-01-01
  • 2017-01-22
  • 2017-07-15
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-13
相关资源
最近更新 更多