Android中的HTML5画布问题
我想用画布制作渐变文本,我的电脑渲染代码正确,但 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);
}
I want to make a gradient text with canvas and my pc renders the code correct, but android displays it like normal gradient with the text inside of it. How can i solve this problem, if it's possible?
Here's the 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很遗憾地说,这是一个错误。
或者更确切地说,fillText 的渐变尚未在 Android 浏览器上实现。如果你这样写:
你会看到文本和矩形在 Chrome 中都有渐变。
在这里观看直播。
但在 Android 设备上,文本将是红色,矩形将是渐变!
Chrome 本身仍然没有完全支持规范作者(他本人是 Google 员工)提出的所有画布渐变情况。我在此处提交了有关该问题的错误报告。
Sorry to say, it's a bug.
Or rather, the gradient for fillText is not yet implemented on the android browser. If you write this:
You will see that both the text and the rectangle have the gradient in Chrome.
See it live here.
But on the android device the text will be red and the rect will be a gradient!
Chrome itself still doesn't have full support for all the canvas gradient cases that were laid out by the specification author (himself a Google employee). I submitted a bug report about it here.