Link to home
Start Free TrialLog in
Avatar of ExtremeFitness
ExtremeFitness

asked on

VB.Net How do i get an image out of my Resource file ??

VB.Net How do i get an image out of my Resource file at runtime??


ASKER CERTIFIED SOLUTION
Avatar of Ramuncikas
Ramuncikas
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tpwells
tpwells

if the image is an embedded resource you can use this function:

    Public Function RetrieveEmbeddedImage(ByVal ImageFileName As String) As Image
        ImageName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name & "." & ImageFileName
        Dim img As Image
        Dim strm As Stream = _
        System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(ImageFileName)
        If Not strm Is Nothing Then
            img = Image.FromStream(strm)
        End If
        strm.Close()
        Return img
    End Function
sorry hit submit to quickly...

ImageFileName = the name of the embedded file.

Also this works best if there are no spaces in your solution and project names.
Avatar of Mike Tomlinson
For embedded resources you can use this instead:

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = new Bitmap(this.GetType(), "myImage.jpg");
        }
VB.Net would be:

    PictureBox1.Image = New Bitmap(Me.GetType(), "myImage.jpg")