Link to home
Start Free TrialLog in
Avatar of jxharding
jxharding

asked on

cant get bitmap to be used as embedded resource, code supplied

hi, i cant get 2 bitmaps to be seen as embedded resources.
i copied the bitmaps out of syncfusions datagridbuttons demo.
i added them by  using the solution explorer > add existing item.
i also tried adding them by File > Add Existing item
i set the files' build action to embedded resource.
i also tried the build action on content.
i have spent a lot of time on this and its as if theres a connection i need to make before it can see
the files as embedded resources. i did compile it first before i ran it in debug mode.
i just get the error

An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll
Additional information: 'null' is not a valid value for 'stream'.

in this section:
  Dim streamBitMap As System.IO.Stream = assemblyExecution.GetManifestResourceStream(BitMapName)
  Dim bitmapEmbedded As Bitmap = New Bitmap(streamBitMap)

here is all the code, you need 2 bitmaps, one called buttonface.bmp and buttonfacepressed.bmp
but its all available at www.tapeus.co.za/download/eeicon.zip

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private WithEvents Icons As ImageList
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private _buttonFace As Bitmap
    Private _buttonFacePressed As Bitmap

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Attempt1()
        Attempt2()
    End Sub
    Private Sub Attempt1()
        Dim strm As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("buttonface.bmp")
        _buttonFace = New Bitmap(strm)
        strm = Me.GetType().Assembly.GetManifestResourceStream("buttonfacepressed.bmp")
        _buttonFacePressed = New Bitmap(strm)
    End Sub
    Private Sub Attempt2()
        _buttonFace = GetEmbeddedBitmap("buttonface.bmp")
        _buttonFacePressed = GetEmbeddedBitmap("buttonfacepressed.bmp")
    End Sub
    Public Function GetEmbeddedBitmap(ByVal BitMapName As String) As Bitmap
        Dim assemblyExecution As System.Reflection.Assembly = Me.GetType.Assembly.GetEntryAssembly()
        Dim namespaceName As String = assemblyExecution.GetName().Name.ToString()
        BitMapName = namespaceName & "." & BitMapName
        Dim streamBitMap As System.IO.Stream = assemblyExecution.GetManifestResourceStream(BitMapName)
        Dim bitmapEmbedded As Bitmap = New Bitmap(streamBitMap)
        Return bitmapEmbedded
    End Function
End Class
SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America 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 RonaldBiemans
RonaldBiemans

Hi jxharding,

Your attemps where correct, you just forgot to set the build action for your bitmaps to embedded resource.
Right click on your bitmap choose properties and set the build action to embedded resource
ASKER CERTIFIED SOLUTION
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