相关疑难解决方法(0)

画布中的矩形尺寸错误

我正在实施一个颜色选择器.渲染有问题.当我调用c.fillRect(0, 0, 100, 80);该矩形的大小是103x42 px而不是100x80.这有什么不对?

此外,矩形是抗锯齿的.我是否需要将位置偏移(0.5,0.5)以避免AA?我没有使用任何类型的坐标系转换.

colorSlider = function($e, color) {
    this._$canvas = $('<canvas></canvas>');
    this._c = this._$canvas[0].getContext('2d');
    this._color = color || { r: 0, g: 0, b: 0 };
    this._$canvas.width('310px');
    this._$canvas.height('80px');
    $e.append(this._$canvas);
    this._render();
    var me = this;
    this._$canvas.mousedown(function(e) { me._mouseDown.call(me, e) });
    this._$canvas.mouseup(function(e) { me._mouseUp.call(me, e) });
    this._$canvas.mousemove(function(e) { me._mouseMove.call(me, e) });
    this._dragChannel = 0;
}

colorSlider.prototype._pointInRect = function(x, y, rect) {
    return x >= rect.x && x <= rect.x + rect.w && y >= rect.y && y …
Run Code Online (Sandbox Code Playgroud)

html5 2d canvas

9
推荐指数
1
解决办法
4916
查看次数

QT 5.7 QML快速半透明矩形,一侧带有圆角

我想要使​​用Qt Quick QML的半透明矩形,但仅在一侧具有圆角。

这是我想要的矩形的形状。如果看不到,我可能会重叠2个矩形,一个带有圆角,另一个没有。但是,这不适用于透明度,因为重叠会变暗。

     ----------|
   /           |
 /             | 
|              |
|              |
|              |
 \             | 
   \           |   
     ----------|
Run Code Online (Sandbox Code Playgroud)

有人有什么想法吗?

qt qml qtquickcontrols qt5.7

5
推荐指数
1
解决办法
2065
查看次数

带圆角的html5画布三角形

我是 HTML5 Canvas 的新手,我正在尝试绘制一个带圆角的三角形。

我试过了

ctx.lineJoin = "round";
ctx.lineWidth = 20;
Run Code Online (Sandbox Code Playgroud)

但他们都没有工作。

这是我的代码:

ctx.lineJoin = "round";
ctx.lineWidth = 20;
Run Code Online (Sandbox Code Playgroud)
var ctx = document.querySelector("canvas").getContext('2d');

ctx.scale(5, 5);
    
var x = 18 / 2;
var y = 0;
var triangleWidth = 18;
var triangleHeight = 8;

// how to round this triangle??
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + triangleWidth / 2, y + triangleHeight);
ctx.lineTo(x - triangleWidth / 2, y + triangleHeight);
ctx.closePath();
ctx.fillStyle = "#009688";
ctx.fill();
    
ctx.fillStyle = "#8BC34A";
ctx.fillRect(0, triangleHeight, 9, 126); …
Run Code Online (Sandbox Code Playgroud)

html javascript canvas

3
推荐指数
3
解决办法
2542
查看次数

如何在Canvas中制作药丸形状?(基本上是圆角矩形)

正在玩一个突破性的克隆并想要制作圆角的道具。

有人能指出我正确的方向吗?

谢谢!

html canvas

2
推荐指数
1
解决办法
5019
查看次数

标签 统计

canvas ×3

html ×2

2d ×1

html5 ×1

javascript ×1

qml ×1

qt ×1

qt5.7 ×1

qtquickcontrols ×1