我正在实施一个颜色选择器.渲染有问题.当我调用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) 我想要使用Qt Quick QML的半透明矩形,但仅在一侧具有圆角。
这是我想要的矩形的形状。如果看不到,我可能会重叠2个矩形,一个带有圆角,另一个没有。但是,这不适用于透明度,因为重叠会变暗。
----------|
/ |
/ |
| |
| |
| |
\ |
\ |
----------|
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗?
我是 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)正在玩一个突破性的克隆并想要制作圆角的道具。
有人能指出我正确的方向吗?
谢谢!