在 .exe 中编译映像 vb.net
Compile image in .exe vb.net
我想在 vb.net 中制作一个简单的 .exe 应用程序。该应用程序不会在 .exe 文件上安装纯 运行。
申请有一张表格,两张图片。当我在图像上设置选项以构建操作时 - 编译
Unable to open module file 'C:\Users\t3cho\documents\visual studio 2013\Projects\Apps\Apps\Resources\power.png': System Error &H80041feb&
有没有其他方法可以在没有安装或额外文件夹的情况下制作带有图像的 .exe 文件。
是的。它被称为嵌入式资源。将图片的 Build Action
设置为 Embedded Resource
。然后你可以像这样在运行时获取图像:
Try
_assembly = [Assembly].GetExecutingAssembly()
_imageStream = _assembly.GetManifestResourceStream("MyNameSpace.MyImage.png")
' Do something with _imageStream
Catch ex As Exception
' Resource not found or something went wrong
End Try
将图像(和其他类型的资源)包含到应用程序中的最简单方法是右键单击项目,转到 "Resources"-Tab 并在其中添加图像。您可以将其名称更改为例如MyEmbeddedImage
并像这样访问它
Dim img As Image = Properties.Resources.MyEmbeddedImage
或
Dim img As Image = My.Resources.MyEmbeddedImage
这会自动将 Build Action
设置为 None。
注意:此方法是类型安全的,如果图像丢失,您将在编译时出错。
参见:My.Resources Object and How to: Add or Remove Resources
如果您仍想嵌入图像 "manually",您必须将 Build Action
设置为 嵌入式资源 并按照@Icemanind 描述的方式访问它。
我想在 vb.net 中制作一个简单的 .exe 应用程序。该应用程序不会在 .exe 文件上安装纯 运行。
申请有一张表格,两张图片。当我在图像上设置选项以构建操作时 - 编译
Unable to open module file 'C:\Users\t3cho\documents\visual studio 2013\Projects\Apps\Apps\Resources\power.png': System Error &H80041feb&
有没有其他方法可以在没有安装或额外文件夹的情况下制作带有图像的 .exe 文件。
是的。它被称为嵌入式资源。将图片的 Build Action
设置为 Embedded Resource
。然后你可以像这样在运行时获取图像:
Try
_assembly = [Assembly].GetExecutingAssembly()
_imageStream = _assembly.GetManifestResourceStream("MyNameSpace.MyImage.png")
' Do something with _imageStream
Catch ex As Exception
' Resource not found or something went wrong
End Try
将图像(和其他类型的资源)包含到应用程序中的最简单方法是右键单击项目,转到 "Resources"-Tab 并在其中添加图像。您可以将其名称更改为例如MyEmbeddedImage
并像这样访问它
Dim img As Image = Properties.Resources.MyEmbeddedImage
或
Dim img As Image = My.Resources.MyEmbeddedImage
这会自动将 Build Action
设置为 None。
注意:此方法是类型安全的,如果图像丢失,您将在编译时出错。
参见:My.Resources Object and How to: Add or Remove Resources
如果您仍想嵌入图像 "manually",您必须将 Build Action
设置为 嵌入式资源 并按照@Icemanind 描述的方式访问它。