【问题标题】:RadioButtonRenderer with Transparent Background具有透明背景的 RadioButtonRenderer
【发布时间】:2011-07-13 01:45:43
【问题描述】:

我需要将单选按钮呈现给 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());

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

【问题讨论】:

    标签: c# winforms drawing radio-button


    【解决方案1】:

    不确定您的按钮看起来如何,但使用带有灰色的 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      相关资源
      最近更新 更多