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??


LVL 2
ExtremeFitnessAsked:
Who is Participating?
 
RamuncikasConnect With a Mentor Commented:
My.Resources.MyImageResourceName
0
 
tpwellsCommented:
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
0
 
tpwellsCommented:
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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
For embedded resources you can use this instead:

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

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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.