Tech Blog‎ > ‎

VB.NET - Extract an Image Embedded as a Resource

posted Feb 19, 2010, 1:58 PM by Victor Zakharov
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:
 

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

This is not even mine, honestly. However, 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".

Comments