c#中如何在已知图片上画圆?

pictureBox2.Image = curBitmap;//curBitmap是传进去的图片
Graphics gra = this.pictureBox2.CreateGraphics();
Pen pen = new Pen(Color.Pink);//画笔颜色
gra.DrawEllipse(pen, 10, 10, 100, 100);//画椭圆的方法,x坐标、y坐标、宽、高,如果是100,则半径为50
为什么不能在图片上显示出所画的圆?

pictureBox2.BackgroundImage = curBitmap;
试试

Graphics ga 会画在 创建它的Handler上。

你创建自 pictureBox,那么就是画在 pictureBox上的,而 pictureBox.Image 是呈现在 pictureBox之上的,所以覆盖了。
要么 设置为 BackGroundImage,成为 pictureBox 的底层。
要么直接画在 image上
ga = Graphics.FromImage(pictureBox2.Image);追问

谢谢,用pictureBox2.BackgroundImage = curBitmap;可以的 但是本身图片是800*600的,设置的pictureBox的大小是200*150,sizemode用的stretchimage,用了这句话之后,图片大小就还原了,没办法在pictureBox上显示全部。(这个星期刚学C#和图像处理,所以很多都不懂)

追答

虽然没太明白你的意思,但 背景图也是有 缩放模式的:
this.pictureBox_Main.BackgroundImageLayout = ImageLayout.Stretch;
网速有点卡,刷半天。

追问

成功了 谢谢你

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-02-28
因为你设置的 curBitmap 是给 Image 属性了,它会不断 OnPaint(),而你用 CreateGraphics 只画一次很快就被原图片刷掉了。

所以如果要用这种方法,需要给 BackgroundImage 赋值而不是 Image。
第2个回答  2014-02-28
你在外面画,界面一重绘就啥都没了,你注册下picturebox2的Paint事件,在Paint事件里画就可以了。
第3个回答  2014-02-28
你画在控件上了, 画的东西会被刷掉, 你画图片上就好了
相似回答
大家正在搜