简体   繁体   English

Canvas:剪辑后的clearRect导致Firefox出现问题

[英]Canvas: clearRect after clip causes an issue in Firefox

I've faced weird issue using canvas clearRect in Firefox. 我在Firefox中使用canvas clearRect遇到了奇怪的问题。 If clipping region is set, clearRect() redraws a content which is outside both clipping region and rectangle to clear. 如果设置了剪切区域,则clearRect()重绘一个在剪切区域和矩形之外的内容以清除。 Since it redraws it over this causes an issue. 因为它重写它会导致问题。 It works correct in other browsers, like Chrome and IE - clearRect doesn't affect the content outside clipping region. 它在其他浏览器中运行正常,如Chrome和IE - clearRect不会影响剪辑区域外的内容。

Here's the code: 这是代码:

        var canvas = document.getElementById("test");
        var context = canvas.getContext('2d');

        context.fillStyle = 'rgba(255, 0, 0, 0.1)';
        context.fillRect(0, 0, 40, 40);

        context.beginPath();
        context.rect(0, 0, 20, 20);
        context.clip();

        context.clearRect(10, 10, 20, 20); // causes an issue, see example below

Code in action: http://jsfiddle.net/P8fyP/4/ 行动准则: http//jsfiddle.net/P8fyP/4/

I tested your code at firefox 18 and firefox nightly 21 and I can't find a problem. 我在firefox 18和firefox每晚21测试你的代码,我找不到问题。 The code do what it is supposed to do. 代码执行它应该做的事情。

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

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