android - android问题中的HTML5 Canvas

标签 android html canvas

我想用 Canvas 制作一个渐变文本,我的电脑渲染代码正确,但 android 显示它就像普通渐变一样,里面有文本。如果可能的话,我该如何解决这个问题?
这是 JavaScript:

function text() {
var canvas = document.getElementById('header-text');
var ctx = canvas.getContext('2d');
var gradient = ctx.createLinearGradient(0, 0, 0, 29);
gradient.addColorStop(0, "#fcfcfc");
gradient.addColorStop(1, "#ccc");
ctx.font = "bold 29px helvetica, arial, sans-serif";
ctx.shadowColor = "#232323";
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
ctx.shadowBlur = 2;
ctx.fillStyle = gradient;
ctx.fillText("Company name", 0, 23);
}

最佳答案

很抱歉,这是一个错误。

或者更确切地说,fillText 的渐变尚未在 android 浏览器上实现。如果你这样写:

var gradient = ctx.createLinearGradient(0, 0, 0, 29);
gradient.addColorStop(0, "#fcfcfc");
gradient.addColorStop(1, "#ccc");
ctx.fillStyle = 'red';
ctx.fillStyle = gradient; // replace the fillstyle with a gradient
ctx.fillText("Testing", 0, 23);
ctx.fillRect(0,0,20,20)

您会看到文本和矩形在 Chrome 中都有渐变。

See it live here .

但在 android 设备上,文本将是红色的,矩形将是渐变的!

Chrome 本身仍然不完全支持规范作者(他自己是 Google 员工)提出的所有 Canvas 渐变案例。我提交了一份关于它的错误报告 here .

关于android - android问题中的HTML5 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5585502/

相关文章:

javascript - 如何在 mailto 链接中附加 Canvas 图像?

html - 点击 map 示例对我不起作用

android - Google place api,想要获得最近的位置

android - 在 Reh Hat Linux 上启用 USB Debug模式

html - 在 Angular 应用程序中,<a> 中的 href 不会重新加载页面

html - IE 忽略响应头中的 X-UA-Compatible IE=edge

android - Android Proguard问题

android - 升级到 Android Studio (2020.3.1) Canary 15 导致 Compose 构建错误

javascript - HTML5 Canvas : Can I draw a shape and give it a variable name?

javascript - 使用单击选项在 Canvas 中绘制圆圈