使用 Ruby Gosu,我以这种方式绘制图像:
@background_image.draw(0, 0, 0)
Run Code Online (Sandbox Code Playgroud)
图像比窗口大,有没有办法神奇地调整它的大小以适应窗口?我试图避免硬编码factor_x和factor_y.
在Android中是否可以使用路径以编程方式绘制一条线,这样中间部分是纯色但两端都从该颜色淡化为透明?路径将是一系列计算出的坐标。
我还没有能够建立一个真正可靠的代码来将一个矩形放在另一个矩形中。
我想让“RectangleToCenter”的中心点与“SourceRectangle”的中心点匹配。不应该涉及缩放。
我目前的尝试是
Public Sub CenterRect(ByVal uMain As Rectangle, ByRef uRectToCenter As Rectangle)
Dim iAVHeightHalf As Integer = uMain.Height / 2 'src y center
Dim iAVWidthHalf As Integer = uMain.Width / 2 'src x center
Dim iStartDestX As Integer = uMain.Left + (uRectToCenter.Width / 2) - iAVWidthHalf
Dim iStartDestY As Integer = uMain.Top + (uRectToCenter.Height / 2) - iAVHeightHalf
Dim nNewStart As New Point(iStartDestX, iStartDestY)
uRectToCenter.Location = nNewStart
End Sub
Run Code Online (Sandbox Code Playgroud)
但对我来说它看起来并不干净。
我们公司想为我们的员工打印员工卡,所以我们准备了一个模板,其中包含每个人的照片、姓名和部门的占位符。
我们有一个数据库表,其中包含每个人的照片、姓名和部门的路径。
我想知道是否有可能遍历该表并将人员数据添加到卡片模板中并保存。
我正在使用 C#.Net,但如果您因此而知道更好的解决方案,我很乐意倾听。

我有那个绘图逻辑:
Draw = function(canvas, ctx, mousePosition) {
var grad = ctx.createLinearGradient(0, 0, canvas[0].width, 0);
grad.addColorStop(0, currentLineColor);
grad.addColorStop(1, currentLineColor);
ctx.lineWidth = currentLineWidth;
ctx.strokeStyle = grad;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.globalAlpha = 0.4;
ctx.beginPath();
ctx.moveTo(lastMousePosition.x, lastMousePosition.y);
ctx.lineTo(mousePosition.x, mousePosition.y);
ctx.stroke();
};
Run Code Online (Sandbox Code Playgroud)
当我在此代码中设置 globalAlpha 以设置不透明度时,会看到我绘制的线条中的点。此逻辑附加到 mosemove 事件。
我想当我点击按钮时,向表单添加一个矩形
我可以在表单中添加我想要多少但我无法通过点击按钮添加像矩形这样的形状,我搜索了它,但我没有找到解决方案
这里有人知道怎么做吗?
这是我在表单绘制中的代码
private void Form1_Paint(object sender, PaintEventArgs e)
{
locationX = locationX + 20;
locationY = locationY + 20;
e.Graphics.DrawRectangle(Pens.Black,
new Rectangle(10 + locationX, 10 + locationY, 50, 30));
}
Run Code Online (Sandbox Code Playgroud)
这是我的按钮代码
private void button1_Click(object sender, EventArgs e)
{
this.Paint += Form1_Paint;
}
Run Code Online (Sandbox Code Playgroud)
但是当我单击按钮时它不起作用。为什么它不工作?
我想将以下示例中使用的颜色更改为棕色,但我的尝试无效:
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.RED);
Run Code Online (Sandbox Code Playgroud)
这不起作用:
mPaint.setColor(Color.Brown);
Run Code Online (Sandbox Code Playgroud)
这也不是:
mPaint.setColor(mPaint.setColor(0x00994C00));
Run Code Online (Sandbox Code Playgroud)
它仅在我将颜色更改为RED, GREEN, BLUE, CYAN,时才有效MAGENTA。
有人可以帮我解决这个问题吗?
假设我有一个简单的画布元素,并在其上绘制复杂的资源密集型图片。然后我在图片上画了一些简单的线条。有没有办法“保存”画布的状态(在绘制线条之前),然后重绘状态以擦除所做的任何进一步更改。我确实尝试过save(),restore()但我认为它的状态不包括画布上的当前形状。请参阅下面的演示。
var canvas = document.getElementById("canvas");
var context = canvas.getContext('2d');
function init() {
// This is some computationally intensive drawing we don't want to repeat
context.fillStyle = "rgb(150,29,28)";
context.fillRect(40, 40, 255, 200);
context.fillStyle = "rgb(150,83,28)";
context.fillRect(10, 10, 50, 50);
context.fillStyle = "rgb(17,90,90)";
context.fillRect(5, 100, 200, 120);
context.fillStyle = "rgb(22,120,22)";
context.fillRect(200, 200, 90, 90);
// Now we save the state so we can return to it
saveState();
}
function lines() {
// This is some drawing we will …Run Code Online (Sandbox Code Playgroud)I am using OpenLayers to create a map that allows a user to draw on it. The drawing options are implemented from the official docs and do work. https://openlayers.org/en/latest/examples/draw-features.html
I tried to give the user an option to delete his former drawing. By holding the key "A" you can see the users selection. Now this selected drawings should be deleted in the moment the key is released (but nothing happened).
var select = new Select();
window.addEventListener('keydown', function (event) {
// …Run Code Online (Sandbox Code Playgroud) 我需要有关如何制作事件和在网格中绘制鼠标线的建议。不知何故,我不能这样做,所以我可以在网格中绘制直线。但是我仍然有一个网格,我不知道如何修复绘图错误。我在下面添加我的 Javascript 代码。我的鼠标绘图事件不起作用,它根本不吸引我。
网格的JS代码:
;(function () {
let canvas, ctx, mouse
class Mouse {
constructor (ctx, x = 0, y = 0) {
this.x = x
this.y = y
this.ctx = ctx
}
set pos (evt) {
const canvasDimensions = canvas.getBoundingClientRect()
this.x = Math.floor(evt.clientX - canvasDimensions.left)
this.y = Math.floor(evt.clientY - canvasDimensions.top)
const { x, y, ctx } = this
const txt = `X: ${x}, Y: ${y}`
ctx.font = '16px Poppins'
const offsetX = x < canvas.width / 2 ? 15 …Run Code Online (Sandbox Code Playgroud) drawing ×10
javascript ×4
canvas ×3
android ×2
c# ×2
html ×2
.net ×1
colors ×1
events ×1
graphics ×1
libgosu ×1
mouseevent ×1
node.js ×1
openlayers ×1
paint ×1
rectangles ×1
ruby ×1
vb.net ×1
winforms ×1