This page looks best with JavaScript enabled

VB.NET - Extract an Image Embedded as a Resource

 ·   ·  ☕ 1 min read

Here’s one of the ways to embed an image into EXE file:

  1. Left click the file in the project tree
  2. Set Build Action -> Embedded Resource.

And how you can access this file in code:

1
2
3
4
5
6
Imports System.Reflection.Assembly

'returns an embedded resource image by name
Public Function EmbeddedImage(ByVal Name As String) As Bitmap
  Return New Bitmap(GetExecutingAssembly.GetManifestResourceStream(Name))
End Function

It’s the shortest piece of code I found on the net. And it works, even for GIFs with transparent backgrounds, which is what I needed it for.

Parameter Name should be a fully qualified name of the file you are referring to (Namespace + file name). If your project’s name is MyApplication1, chances are that you need something like MyApplication1.SomePicture.gif.


Victor Zakharov
WRITTEN BY
Victor Zakharov
Web Developer (Angular/.NET)