[英]Put a shape on pictureBox, c#
I have a pictureBox, I need to put some ovalshapes on different places over the pictureBox.. 我有一个PictureBox,我需要在pictureBox的不同位置放置一些椭圆形。
In some reason the shapes are behind the picture and they unseen.. 由于某种原因,形状位于图片的后面,因此看不见。
Can I do something that the shapes will be over the picture and not behind it..? 我可以做一些使形状在图片上而不是图片后面的事情吗?
What property change this? 什么属性会改变?
To paint some oval shapes you use a List<Rectangle> ovals = List<Rectangle>();
要绘制一些椭圆形,请使用
List<Rectangle> ovals = List<Rectangle>();
To draw them you have a choice of 要绘制它们,您可以选择
For the former you need to create the Graphics
object from the Image
you want to change: 对于前者,您需要从要更改的
Image
创建Graphics
对象:
Bitmap bmp = new Bitmap(pictureBox1.Image);
using (Graphics graphics = Graphics.FromImage(bmp))
foreach (Rectangle R in ovals)
graphics.FillEllipse(yourBrush, R.X, R.Y, R.Width, R.Height);
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
pictureBox1.Image = bmp;
This code will change the pixels and can be put anywhere. 此代码将更改像素,可以放置在任何地方。
For the latter you use the Paint
event: 对于后者,您可以使用
Paint
事件:
foreach (Rectangle R in ovals)
e.Graphics.FillEllipse(yourBrush, R.X, R.Y, R.Width, R.Height);
This version will only change the surface of the PicureBox and needs to be put in or be triggered from the Paint event. 此版本仅会更改PicureBox的表面,需要放入或从Paint事件中触发。
I think you want this version.. 我想你想要这个版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.