从Winforms Form/Button/Image属性中提取本地资源图像
我有一个现有的 Winforms 应用程序,其中有多个表单,每个表单的两个主按钮(“确定”和“取消”)上具有相同的按钮图像。通过将 Button 的 Image 属性设置为“本地资源”并导入所需的图像,在 VS 设计器中设置图像。
我无权访问原始图像文件。如何从以这种方式设置 Image 属性的 Button 控件的 Image 属性中提取图像?
I have an existing Winforms app that has several forms with the same button images on the two primary buttons for each form (OK and Cancel). The images are set in the VS Designer by setting Image property of Button to "Local resource" and importing the desired image.
I do not have access to the original image files. How do I extract an image from the Image property of a Button control whose Image property has been set this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了一个比手动解码 Base64 更简单的方法。
假设您的表单名为 Form1:
这适用于持久性设置为“嵌入在 .resx 中”的资源。如果持久性是“在编译时链接”,则图像已作为文件存在于项目的资源目录中。
I found a much easier method than manually decoding the Base64.
Assuming your form is called Form1:
This applies to resources with Persistence set to "Embedded in .resx". If Persistence is "Linked at compile time" the image already exists as a file in your project's Resources directory.
实际上,图像并不存储在文件系统中,而是作为 Base64 编码的序列化表示添加到表单的 resx 文件(例如 MainForm.resx)中。如果您知道如何操作,则可以对该字符串进行 Base64 解码,将结果保存在平面文件中并正确命名(您必须知道其图像类型)。
Actually the images are not stored in the filesystem, but rather added to the resx file of your Form (e.g. MainForm.resx) as a base64-encoded serialized representation. If you know how to, you could base64-decode that string, save the result in a flatfile and name it correctly (you must know the image type for that).