简体   繁体   English

如何通过 C# 代码生成图像?

[英]How do I generate an Image through C# code?

I've got a button in my WinForms plugin.我的 WinForms 插件中有一个按钮。 It's got an image on it.它上面有图像。 The thing is, when I click the button, I want the image to change from whatever image it is now, to whatever image I want it to be.问题是,当我单击按钮时,我希望图像从现在的任何图像变为我想要的任何图像。

So basically how do i make button change its image?所以基本上我如何让按钮改变它的形象? The image type is System.Drawing.Image .图像类型是System.Drawing.Image

In order to change a Button 's image in WinForms you set it's Image property.为了在 WinForms 中更改Button的图像,您需要设置它的Image属性。 You can either load a bitmap from a file with Bitmap.FromFile , or you can draw an image using the Graphic class by creating a new instance of Bitmap using the Width/Height constructor (ie new Bitmap(100, 100) ) and then use the Graphic.FromImage method. You can either load a bitmap from a file with Bitmap.FromFile , or you can draw an image using the Graphic class by creating a new instance of Bitmap using the Width/Height constructor (ie new Bitmap(100, 100) ) and then use Graphic.FromImage方法。 Lookup the documentation on the Graphic class for more info.Graphic class 上查找文档以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 C# 代码(不是 XAML)旋转在 WPF 中单击按钮时动画的图像 - How do i rotate an image animated on button click in WPF through C# code (Not XAML) 如何从WADL文件生成C#代码? - How do I generate C# code from WADL files? 如何使用 XMLWriterClass 在 C# 中生成以下 Xml 代码? - How do I generate the following Xml code in C# with XMLWriterClass? iText 7 如何在 C# 中生成数据矩阵码 - iText 7 how do I generate a Data Matrix code in C# 如何用代码替换面板上的背景图像? C# - How do I replace a background image on a panel in code? C# c# Razor 页面,EF Core,如何通过代码生成子记录并将其添加到尚未使用添加的父记录中 - c# Razor Pages, EF Core, How do I generate and add Child Records through Code to a Parent Record that has yet to be added using 如何在 UWP 中对齐我通过代码生成的元素? - How do i align an Element in UWP that i generate through code? 如何在C#中使用固定字符生成随机数循环? - how do i generate random number loop with fix char code in c#? 如何在C#源代码中生成COM互操作代理? - How do I generate COM interop proxies into C# source code? 如何在 C# 中生成 .proto 文件或使用“Code First gRPC” - How do I generate .proto files or use 'Code First gRPC' in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM