开发者

RadioButtonRenderer with Transparent Background

I have a situation where I need开发者_开发问答 to render a radio button to an 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());

This works except that it's drawing the default control-grey as the background. How can I set this the background color to Transparent?


Not sure how your button looks exactly, but using the Bitmap.MakeTransparent Method with the grey color should work.

If it is not to your liking, you can try more complex color transformation using the 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜