Opera:在 JavaScript 中绘制椭圆形时出现问题

发布于 2024-11-29 04:13:14 字数 1020 浏览 4 评论 0原文

只是为了好玩和学习的目的,我目前正在编写一个基于 javascript 的绘画应用程序,但是我在椭圆形的绘制代码方面遇到了一些跨浏览器问题。

这是我的代码,简化为一个简单的椭圆函数:

function Oval(context, x, y, radiusX, radiusY, color, filled) {
  if ((radiusX === 0) || (radiusY === 0)) {
    return;
  }
  context.save();
  context.translate(x, y);
  if (radiusX !== radiusY) {
    context.scale(1, radiusY / radiusX);
  }
  context.beginPath();
  context.arc(0, 0, radiusX, 0 , 2 * Math.PI);
  context.closePath();
  context.restore();
  if (filled === true) {
    context.fillStyle = color;
    context.fill();
  } else {
    context.strokeStyle = color;
    context.stroke();
  }
}

var ctx = c.getContext("2d");
Oval(ctx, 150, 150, 100, 149, "#663399", false);
<canvas id="c" width="300" height="300"></canvas>

这在当前稳定版本的 Firefox、Chrome、Internet Explorer 和 Safari 中效果很好。但Opera似乎并不喜欢它。可能是什么问题?

just for fun and for learning purposes, I'm currently writing a javascript-based paint application, but I've experienced a little cross-browser problem with the drawing code of the oval shape.

Here's my code, reduced to a simple oval function:

function Oval(context, x, y, radiusX, radiusY, color, filled) {
  if ((radiusX === 0) || (radiusY === 0)) {
    return;
  }
  context.save();
  context.translate(x, y);
  if (radiusX !== radiusY) {
    context.scale(1, radiusY / radiusX);
  }
  context.beginPath();
  context.arc(0, 0, radiusX, 0 , 2 * Math.PI);
  context.closePath();
  context.restore();
  if (filled === true) {
    context.fillStyle = color;
    context.fill();
  } else {
    context.strokeStyle = color;
    context.stroke();
  }
}

var ctx = c.getContext("2d");
Oval(ctx, 150, 150, 100, 149, "#663399", false);
<canvas id="c" width="300" height="300"></canvas>

This works nice in current stable versions of Firefox, Chrome, Internet Explorer and Safari. But Opera doesn't seem to like it. What might be the problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎盛开的樱花 2024-12-06 04:13:14

这是因为 Opera 需要 arcc 的最后一个参数

,因此将其更改为 context.arc(0, 0, radiusX, 0 , 2 * Math.PI, false ); 你就会变得很幸运。

This is because Opera requires the last argument to arc

So change it to context.arc(0, 0, radiusX, 0 , 2 * Math.PI, false); and you'll be golden.

紫竹語嫣☆ 2024-12-06 04:13:14

我们已经在内部版本中修复了这个问题,并且应该很快就会在稳定版本中发布!

We have fixed this in an internal build, and should be out soon in a stable release!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文