GraphicsPath.IsVisible() 与实际路径不匹配?
GraphicsPath.IsVisible() doesn't match up with actual path?
我在 UserControl 的世界坐标中绘制的 GraphicsPath 与 GraphicsPath.IsVisible() 的结果之间存在差异,以使用鼠标点击测试形状。
我做了一个小测试,绘制了一个地图,其中 IsVisible() 返回 true,相对于绘制的 GraphicsPath 形状。结果显示了我正在绘制的形状的非常 "low resolution" 版本。
Link 共享 Google 显示结果的驱动器图像:
http://goo.gl/zd6xiM
是不是我做错了或做错了导致了这个问题?
谢谢!
这是我的大部分 OnMouseMove() 事件处理程序:
protected override void OnMouseMove(MouseEventArgs e)
{
//base.OnMouseMove(e);
debugPixel = Point.Empty;
PointF worldPosition = ScreenToWorld(PointToClient(Cursor.Position));
if (_mouseStart == Point.Empty) // Just moving mouse around, no buttons pressed
{
_objectUnderMouse = null;
// Hit test mouse position against each canvas object to see if we're overtop of anything
for (int index = 0; index < _canvasObjects.Count; index++) // Uses front to back order
{
NPCanvasObject canvasObject = _canvasObjects[index];
if (canvasObject is NPCanvasPart)
{
NPCanvasPart canvasPart = (canvasObject as NPCanvasPart);
NPPart part = canvasPart.Part;
GraphicsPath gp = canvasPart.GraphicsPath;
// Set the object under the mouse cursor, and move it to the "front" so it draws on top of everythign else
if (gp.IsVisible(worldPosition))
{
// DEBUG
debugPixel.X = e.X;
debugPixel.Y = e.Y;
_objectUnderMouse = canvasObject;
_canvasObjects.MoveItemAtIndexToFront(_canvasObjects.IndexOf(canvasObject));
break; // Since we're modifying the collection we're iterating through, we can't reliably continue past this point
}
}
}
}
else
{
...
}
}
稍后在我的绘图代码中,每当 debugPixel != Point.Empty 时,我都会绘制一个像素。画之前我暂时抑制了清除,所以我可以看到它们。
可能会询问或可能有助于解决问题的其他一些信息:
- 我尝试了不同的 Graphics.InterpolationMode 设置,但似乎没有任何效果
- 我已经将 TranslateTransform 和 ScaleTransform 应用于主绘图 Graphics,但底层 HitTest 贴图似乎缩放和平移等于 GraphicsPath
- 对于我的主绘图 canvas,Graphics.PageUnit = GraphicsUnit.Inch,除非我在做基于像素的叠加层
我以为我已经对此进行了足够彻底的研究,但显然没有。在发布这个问题后不久,我用稍微不同的术语进行了另一次搜索,发现了这个:
http://vbcity.com/forums/t/72877.aspx
...这足以让我知道 GraphicsPath 和我的主要绘图 Graphics 不一样。使用重载 GraphicsPath.IsVisible(PointF, Graphics) 很好地解决了这个问题。
本质上,它试图检查我的形状的一个非常别名(像素化)的版本,该版本已经缩放到相同的大小但没有平滑。
我在 UserControl 的世界坐标中绘制的 GraphicsPath 与 GraphicsPath.IsVisible() 的结果之间存在差异,以使用鼠标点击测试形状。
我做了一个小测试,绘制了一个地图,其中 IsVisible() 返回 true,相对于绘制的 GraphicsPath 形状。结果显示了我正在绘制的形状的非常 "low resolution" 版本。
Link 共享 Google 显示结果的驱动器图像: http://goo.gl/zd6xiM
是不是我做错了或做错了导致了这个问题?
谢谢!
这是我的大部分 OnMouseMove() 事件处理程序:
protected override void OnMouseMove(MouseEventArgs e)
{
//base.OnMouseMove(e);
debugPixel = Point.Empty;
PointF worldPosition = ScreenToWorld(PointToClient(Cursor.Position));
if (_mouseStart == Point.Empty) // Just moving mouse around, no buttons pressed
{
_objectUnderMouse = null;
// Hit test mouse position against each canvas object to see if we're overtop of anything
for (int index = 0; index < _canvasObjects.Count; index++) // Uses front to back order
{
NPCanvasObject canvasObject = _canvasObjects[index];
if (canvasObject is NPCanvasPart)
{
NPCanvasPart canvasPart = (canvasObject as NPCanvasPart);
NPPart part = canvasPart.Part;
GraphicsPath gp = canvasPart.GraphicsPath;
// Set the object under the mouse cursor, and move it to the "front" so it draws on top of everythign else
if (gp.IsVisible(worldPosition))
{
// DEBUG
debugPixel.X = e.X;
debugPixel.Y = e.Y;
_objectUnderMouse = canvasObject;
_canvasObjects.MoveItemAtIndexToFront(_canvasObjects.IndexOf(canvasObject));
break; // Since we're modifying the collection we're iterating through, we can't reliably continue past this point
}
}
}
}
else
{
...
}
}
稍后在我的绘图代码中,每当 debugPixel != Point.Empty 时,我都会绘制一个像素。画之前我暂时抑制了清除,所以我可以看到它们。
可能会询问或可能有助于解决问题的其他一些信息:
- 我尝试了不同的 Graphics.InterpolationMode 设置,但似乎没有任何效果
- 我已经将 TranslateTransform 和 ScaleTransform 应用于主绘图 Graphics,但底层 HitTest 贴图似乎缩放和平移等于 GraphicsPath
- 对于我的主绘图 canvas,Graphics.PageUnit = GraphicsUnit.Inch,除非我在做基于像素的叠加层
我以为我已经对此进行了足够彻底的研究,但显然没有。在发布这个问题后不久,我用稍微不同的术语进行了另一次搜索,发现了这个:
http://vbcity.com/forums/t/72877.aspx
...这足以让我知道 GraphicsPath 和我的主要绘图 Graphics 不一样。使用重载 GraphicsPath.IsVisible(PointF, Graphics) 很好地解决了这个问题。
本质上,它试图检查我的形状的一个非常别名(像素化)的版本,该版本已经缩放到相同的大小但没有平滑。