C# 带透明背景的RadioButtonRenderer

C# 带透明背景的RadioButtonRenderer,c#,winforms,drawing,radio-button,C#,Winforms,Drawing,Radio Button,我遇到一种情况,需要将单选按钮渲染到System.Drawing.Image System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(20,16); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) { RadioButtonRenderer.DrawRa

我遇到一种情况,需要将单选按钮渲染到System.Drawing.Image

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(20,16);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{                                    
    RadioButtonRenderer.DrawRadioButton(g, new Point(2, 2), RadioButtonState.CheckedPressed);
}
return System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap());

除了将默认控件绘制为灰色作为背景外,此操作有效。如何将背景色设置为透明?

不确定按钮的外观,但使用灰色应该可以

如果您不喜欢,可以使用以下选项尝试更复杂的颜色变换:

ColorMatrix matrix = new ColorMatrix();

// This will change the image's opacity.
matrix.Matrix33 = 0.5f;

ImageAttributes imgAttrs = new ImageAttributes();
imgAttrs.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

g.DrawImage(img, new Rectangle(0, 0, 50, 50), 0, 0, 50, 50, GraphicsUnit.Pixel, imgAttrs);