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

Hos*_*nia 26 c# graphics drawing winforms

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

Mar*_*rco 61

你的意思是:

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

或者你可以使用

Brush brush = new SolidBrush(Color.FromArgb(alpha, red, green, blue))
Run Code Online (Sandbox Code Playgroud)

其中阿尔法从0到255,所以128的阿尔法值会给你50%opactity.