我有一种情况需要将单选按钮渲染到 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());
除将默认的控制灰色绘制为背景外,此方法有效。如何将此背景颜色设置为透明?
最佳答案
不确定您的按钮的外观,但使用 Bitmap.MakeTransparent Method灰色应该可以。
如果您不喜欢,可以使用 ColorMatrix Class 尝试更复杂的颜色转换:
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);
关于c# - 具有透明背景的 RadioButtonRenderer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5266105/