绘制低不透明度的填充矩形

我有一个带有C#语言的Windows窗体应用程序中的图片的PictureBox。我想在picturebox的某个位置绘制一个FillRectangle。但我还需要看到图片框的图片。我可以绘制这个低不透明度的矩形来看图片盒的形象

你的意思是:

using (Graphics g = Graphics.FromImage(pb.Image)) { using(Brush brush = new SolidBrush(your_color)) { g.FillRectangle(brush , x, y, width, height); } } 

或者你可以使用

 Brush brush = new SolidBrush(Color.FromArgb(alpha, red, green, blue)) 

alpha从0到255,所以你的alpha值为128将给你50%的不实际。

您需要根据PictureBox图像创建一个Graphics对象,并在其上绘制您想要的内容:

 Graphics g = Graphics.FromImage(pictureBox1.Image); g.FillRectangle(Brushes.Red, new Rectangle(10, 10, 200, 200)) pictureBox1.Refresh() 

或者根据@Davide Parias的建议,您可以使用Paint事件处理程序:

 private void pictureBox_Paint(object sender, PaintEventArgs e) { e.Graphics.FillRectangle(Brushes.Red, new Rectangle(10, 10, 200, 200)); }