我有一个带有C#语言的Windows窗体应用程序中的图片的PictureBox。我想在picturebox的某个位置绘制一个FillRectangle。但我还需要看到图片框的图片。我可以画出这个矩形低透明度,以查看图片框的图像?
答案 0 :(得分:59)
你的意思是:
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% opactity。
答案 1 :(得分:2)
您需要根据Graphics
图片创建一个PictureBox
对象,并在其上绘制您想要的内容:
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));
}