关于GraphicsPath 有可能是它的问题

bolv6666 2017-03-29 07:49:52

MemoryStream ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Jpeg);
bmp = new Bitmap(ms);

Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias;
Pen mypen=null;
if (线元素类型 == "省界")
{
mypen = new Pen(Color.Black, 4);
}
else if (线元素类型 == "市界")
{
mypen = new Pen(Color.Gray, 3);
}
else if(线元素类型 == "县界")
{
mypen = new Pen(Color.LightGray, 2);
}
else if (线元素类型 == "河流界")
{
mypen = new Pen(Color.Blue, 2);
}

GraphicsPath myPath = new GraphicsPath();
for (int i = 0; i < 线元素.Count; i++)
{
GraphicsPath tmpPath= new GraphicsPath();
if (线元素[i].Length > 1)//
{
tmpPath.AddLines(线元素[i]);
myPath.AddPath(tmpPath, false);//首尾不追加

}
tmpPath.Dispose();
}
g.DrawPath(mypen, myPath);//一次性绘出myPath

g.Dispose();
mypen.Dispose();
myPath.Dispose();
ms.Dispose();


在一个绘制地图的程序里,如果第一次打开地图文件,地图线条显示很正常,但如果再打开一次地图文件就不行了,感觉像是各线元素首尾相连,必须关掉程序重新打开。但明明已经设置了myPath.AddPath(tmpPath, false);//首尾不追加,不知道哪里出了问题
...全文
231 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bolv6666 2017-03-29
  • 打赏
  • 举报
回复
多谢各位,已经发现问题了,地图数据的读取采用了ref,造成多次叠加
xuzuning 2017-03-29
  • 打赏
  • 举报
回复
可能是你的数据问题 重复加载了
bolv6666 2017-03-29
  • 打赏
  • 举报
回复
引用 2 楼 xuzuning 的回复:
应该是,但你已经 myPath.Dispose(); 了,应该又不是 你可换个写法             GraphicsPath myPath = new GraphicsPath();             for (int i = 0; i < 线元素.Count; i++)             {                                 if (线元素[i].Length > 1)//                 {                     myPath.AddLines(线元素[i]);                     myPath.StartFigure()                   }             }             g.DrawPath(mypen, myPath);//一次性绘出myPath
试过了,但还是不行,看来问题不在这里
qq_38057746 2017-03-29
  • 打赏
  • 举报
回复
谢谢啦蛮好的
xuzuning 2017-03-29
  • 打赏
  • 举报
回复
应该是,但你已经 myPath.Dispose(); 了,应该又不是 你可换个写法             GraphicsPath myPath = new GraphicsPath();             for (int i = 0; i < 线元素.Count; i++)             {                                 if (线元素[i].Length > 1)//                 {                     myPath.AddLines(线元素[i]);                     myPath.StartFigure()                   }             }             g.DrawPath(mypen, myPath);//一次性绘出myPath
bolv6666 2017-03-29
  • 打赏
  • 举报
回复
这是第一次打开的

这是第二次打开的

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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