首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jCanvas上的globalCompositeOperation

jCanvas上的globalCompositeOperation
EN

Stack Overflow用户
提问于 2013-01-31 04:20:44
回答 2查看 337关注 0票数 2

如何在jCanvas jQuery插件中集成globalCompositeOperation(或任何其他提供“multiply”颜色操作的插件)?

代码语言:javascript
复制
// How do I get this working? //
var ctx = document.getElementById('canvas').getContext('2d');
ctx.globalCompositeOperation = 'darker';

// With this - //
$("canvas").drawArc({
  fillStyle: "#c7302a",
  x: 100, y: 100,
  radius: 50
});

$("canvas").drawArc({
  fillStyle: "#395797",
  x: 170, y: 100,
  radius: 50,
  opacity: 1
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-31 22:11:46

好的,我解决了。在苦苦挣扎了几个小时后,它太简单了:我使用了context blender插件。

JS代码:

代码语言:javascript
复制
$("#canvasReal").drawArc({ // Draw on the real canvas
  fillStyle: "#c7302a",
  x: 100, y: 100,
  radius: 50
});

$("#canvasOff").drawArc({ // Draw on the off screen canvas
  fillStyle: "#395797",
  x: 150, y: 100,
  radius: 50
});

// Blend off-screen canvas onto the real canvas
    var over = canvasOff.getContext('2d'); 
    var under = canvasReal.getContext('2d');
    over.blendOnto(under,'multiply'); 

HTML代码:

代码语言:javascript
复制
<canvas width="500" height="250" id="canvasReal"></canvas>
<canvas width="500" height="250"id="canvasOff" style="display:none;"></canvas>
票数 1
EN

Stack Overflow用户

发布于 2013-07-18 02:03:09

对于记录,jCanvas有一个compositing属性,该属性的值映射到ctx.globalCompositeOperation

代码语言:javascript
复制
$("canvas").drawArc({
  fillStyle: "#c7302a",
  x: 100, y: 100,
  radius: 50,
  compositing: 'darker'
});

-Caleb

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14612931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档