[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

easy include bitmap question

i have an included bitmap in my solution explorer, where do i find it if i want to show it in my project?

thanks,

~b
0
bramsquad
Asked:
bramsquad
  • 2
  • 2
1 Solution
 
Ignacio Soler GarciaCommented:
You have to do like this:

a) See the properties of the image and set the Generatio Action to "Embedded resource".
b) Use this code to acces it:

Public Function CreateImage(vName As String) As Bitmap
        Dim executingAssembly As System.Reflection.Assembly = Me.GetType.Assembly.GetAssembly(Me.GetType)
        Dim myNamespace As String = executingAssembly.GetName().Name.ToString()

        return New Bitmap(Me.GetType.Assembly.GetAssembly(Me.GetType).GetManifestResourceStream("vName"))
End Function

c) Use the name of the image with the name of the name space. Ex: NameSpace.Image.bmp . Take in mind that capitalization does matter!

SoMoS

0
 
bramsquadAuthor Commented:
im not quite sure i understand your code, plus its giving me an error.  please explain.

this is my code...

    Public Function CreateImage(ByVal vName As String) As Bitmap
        Dim executingAssembly As System.Reflection.Assembly = Me.GetType.Assembly.GetAssembly(Me.GetType)
        Dim myNamespace As String = executingAssembly.GetName().Name.ToString()

        Return New Bitmap(Me.GetType.Assembly.GetAssembly(Me.GetType).GetManifestResourceStream(vName)) '<--ERROR HERE
    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.PictureBox11.Image = CreateImage("optical_illusion_1.jpg")
    End Sub

and this is the error message that im getting...

Additional information: 'null' is not a valid value for 'stream'.

thanks for your help

`~b

0
 
Ignacio Soler GarciaCommented:
Check this:

a) Have you setted the property of the image Generation Action to "Embedded resource"?
b) Have you passed the full name of the image (including capitalization). For example, a image called pPp.bmp into a folder called FOLDER inside a Project called CycleLog must be called "CycleLog.FOLDER.pPp.bmp?

Askme more if you need it

SoMoS
 
0
 
bramsquadAuthor Commented:
thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now