【问题标题】:HTML5 canvas in android problemandroid中的HTML5画布问题
【发布时间】:2011-07-31 22:14:28
【问题描述】:

我想用画布制作一个渐变文本,我的电脑可以正确呈现代码,但 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);
}

【问题讨论】:

  • 你能添加有问题的代码吗?在文本上制作渐变的方法不止一种。

标签: android html canvas


【解决方案1】:

很抱歉,这是一个错误。

或者说,填充文本的渐变还没有在安卓浏览器上实现。如果你这样写:

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 员工)提出的所有画布渐变案例。我提交了一个关于它的错误报告here

【讨论】:

  • 只是添加渐变似乎不适用于arc
猜你喜欢
  • 2014-04-06
  • 2012-06-19
  • 2015-10-24
  • 2021-10-13
  • 1970-01-01
  • 1970-01-01
  • 2011-10-28
  • 2011-11-01
  • 1970-01-01
相关资源
最近更新 更多