关于坐标系转换的问题

open422000 2012-08-29 11:04:55
最近画图遇到了个问题,我把pictureBox 左上角的坐标转换成,中点的坐标后,进行画图,

可是当显示的时候有偏移,我不知道如何转换回来,

我写的代码是

//这个是设备坐标转换成逻辑坐标的,我这是放在自己定义的PictureBox的中间位置
public static void DPtoLP(ref PointF srcPoint, PictureBox pCanvas)
{

srcPoint.X = srcPoint.X - (float)pCanvas.Size.Width / 2;
srcPoint.Y = -srcPoint.Y + (float)pCanvas.Size.Height / 2;

}

//这个是转换回来 ,就是这里出错,
public static void LPtoDP(ref PointF srcPoint, PictureBox pCanvas)
{
srcPoint.X = srcPoint.X + (float)pCanvas.Size.Width / 2;
srcPoint.Y = srcPoint.Y - (float)pCanvas.Size.Height / 2;
}
我在这里转换回来,就是画线的时候

public static void DrawAllLines(Graphics g, PictureBox pCanvas)
{

if (Vector.listPt.Count != 0)
{
Pen pen = new Pen(Color.Blue, 5);


//我这里的listPT是个泛型集合 用来保存PointF对象的。。 里面都是我鼠标记录的点集合

for (int i = 0; i < Vector.listPt.Count; i++)
{
PointF pf = Vector.listPt[i]; //我这里转换 好像不起作用,因为传的是局部变量,可是如果我直接传Vector.listPT[i] 会提示我不能传这个为引用,那我如何改变 我这里面的坐标呢
CoordConvert.LPtoDP(ref pf, pCanvas);
Vector.pointCurrent = pf;//这个是将转换的点 赋值给 当前的点,。。没用 为什么呢
}


if (Vector.listPt.Count >1)
{

g.DrawLines(pen, Vector.listPt.ToArray());
g.DrawLine(pen, Vector.GetLastPoint(), Vector.pointCurrent);
}
else
{
g.DrawLine(pen, Vector.listPt[0], Vector.pointCurrent);
}
}
...全文
142 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
baiwenyu 2012-09-03
  • 打赏
  • 举报
回复
问题出在以下两点: ref 参数, Point是值类型

8,833

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧