在画布上绘制大像素
我正在编写一个应用程序,允许用户在触摸屏显示器上绘图。我目前正在使用下面的方法,效果非常好。该方法产生“高分辨率图像”,因为几乎每个像素都绘制一条线(例如100、100→102、103)。
这是我的问题。我希望用户绘制一个“低分辨率图片”(大像素板),您可以在其中故意看到 50×50 的像素(例如 100, 100 -> 150, 150)。有人知道如何实现这一目标吗?我正在使用 Windows Phone 版 Silverlight。我正在考虑构建一个 50×50 像素的大网格,但可能控件太多。
void FingerMove(object sender, MouseEventArgs e)
{
if (this.IsDrawing)
{
this.DestinationPoint = e.GetPosition(paint);
Line line = new Line
{
Stroke = this.Color,
X1 = this.DestinationPoint.X,
Y1 = this.DestinationPoint.Y,
X2 = this.OriginPoint.X,
Y2 = this.OriginPoint.Y,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
StrokeThickness = 15,
Opacity = 1,
};
Debug.WriteLine(string.Join(",", line.X1, line.Y1, line.X2, line.Y2));
paint.Children.Add(line);
}
this.OriginPoint = this.DestinationPoint;
}
I am writing an app which allow user to draw on a touch screen display. I am currently using the method below and it work very well. This method is producing a “high resolution image” since for almost every single pixel a line is drawn (e.g. 100, 100 -> 102, 103).
Here is my question. I’d like user to draw a “low resolution picture” (big pixels board) where you can intentionally see pixels of 50×50 (e.g. 100, 100 -> 150, 150). Does anybody have an idea on how to accomplish that? I am using Silverlight for Windows Phone. I was thinking about building a big grid of 50×50 pixels, but there might be too many controls.
void FingerMove(object sender, MouseEventArgs e)
{
if (this.IsDrawing)
{
this.DestinationPoint = e.GetPosition(paint);
Line line = new Line
{
Stroke = this.Color,
X1 = this.DestinationPoint.X,
Y1 = this.DestinationPoint.Y,
X2 = this.OriginPoint.X,
Y2 = this.OriginPoint.Y,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
StrokeThickness = 15,
Opacity = 1,
};
Debug.WriteLine(string.Join(",", line.X1, line.Y1, line.X2, line.Y2));
paint.Children.Add(line);
}
this.OriginPoint = this.DestinationPoint;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Amr 有正确的想法。我将向您提供这段代码,但需要注意的是我根本没有测试过它。我从此处获取线段相交算法。
首先,您需要设置一个矩形列表并将它们添加到作为“像素”的画布中:
我们需要这些辅助方法:
然后,在 FingerMove 函数中,我们循环遍历每个矩形以查看它是否相交。如果是,我们改变它的颜色:
@Amr has the right idea. I'll give you this code with the caveat that I haven't tested it at all. I took the line segment intersection algorithm from here.
First, you need to set up a list of Rectangles and add them to the canvas that are your "pixels":
We'll need these helper methods:
Then, in the FingerMove function, we loop through each Rectangle to see if it intersects. If it does, we change its color:
如果您只是想让线条变粗,只需尝试 StrokeThickness 的可能值,直到获得所需的效果。
如果您想通过填充屏幕的大面积(例如(50x50)矩形)来手动绘制线条,您可以执行以下操作:
这将为您提供所需的“对齐网格”线。
If you simply want to make the line thicker, just experiment with possible values of StrokeThickness untill you get the desired effect.
If you want to manually draw the line by filling up large areas of the screen say (50x50) rectangles, you could do the follwing:
This would give you the 'snap to grid' line that you want.