[英]How to save a VisualStyleRenderer to a file
I have a VisualStyleRenderer
as follows: 我有一个VisualStyleRenderer
,如下所示:
VisualStyleRenderer renderer =
new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);
How can I save this to an image file (for example, from within the OnPaint()
function for a form)? 如何将其保存到图像文件(例如,从表单的OnPaint()
函数中)?
You don't save it to a file, you use it in your paint event: 您无需将其保存到文件中,而可以在绘画事件中使用它:
VisualStyleRenderer renderer = new
VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);
Rectangle r = new Rectangle(16, 16, 120, 28);
renderer.DrawBackground(e.Graphics, r);
If you are looking to save the result to a file, then create a bitmap and use the Graphics.FromImage(...)
function to get a graphic to draw on it, then save that image. 如果希望将结果保存到文件中,请创建一个位图,然后使用Graphics.FromImage(...)
函数获取要在其上绘制的图形,然后保存该图像。
Bitmap bitmap = new Bitmap(120, 28);
using (Graphics g = Graphics.FromImage(bitmap)) {
VisualStyleRenderer renderer =
new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);
renderer.DrawBackground(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
}
bitmap.Save(@"...\button.png", ImageFormat.Png);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.