Anel
Anel

Reputation: 63

Compile image in .exe vb.net

I want to make a simple .exe application in vb.net. The application wont have an installation just pure run on .exe file .

Application has one form and two pictures. When i set the option on image to build action - compile

enter image description here

Unable to open module file 'C:\Users\t3cho\documents\visual studio 2013\Projects\Apps\Apps\Resources\power.png': System Error &H80041feb&   

Is there any other way to make an .exe file with images without installation or additional folders.

Upvotes: 1

Views: 2602

Answers (2)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112402

The easiest way to include images (and other types of resources) into the application is to right-click the project, go to the "Resources"-Tab and add the image there. You can change its name to e.g. MyEmbeddedImage and access it like this

Dim img As Image = Properties.Resources.MyEmbeddedImage

or

Dim img As Image = My.Resources.MyEmbeddedImage

This automatically sets the Build Action to None.

Note: This approach is type-safe and you will get errors at compile time, if the image is missing.

See: My.Resources Object and How to: Add or Remove Resources


If you still want to embed the image "manually", you must set the Build Action to Embedded Resource and access it as @Icemanind describes.

Upvotes: 2

Icemanind
Icemanind

Reputation: 48696

Yes. It's called embedded resources. Set your image's Build Action to Embedded Resource. You can then get the image at runtime like so:

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

Upvotes: 0

Related Questions